下面是一个最基本的html代码

<!DOCTYPE html>
<!-- This declaration defines the document as HTML5 -->
<html lang="zh-CN">
<!-- The root element of the HTML document, with language set to Chinese (Simplified) -->

<head>
    <!-- Contains meta-information about the document -->

    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }
    </style>
    <script>
        // JavaScript function that displays an alert when called
        function showMessage() {
            alert("Hello! You clicked the button.");
        }
    </script>


    <meta charset="UTF-8">
    <!-- Sets the character encoding to UTF-8 for proper text display -->

    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- Ensures the webpage is responsive and displays correctly on different devices -->

    <title>My First HTML Page</title>
    <!-- Defines the title of the page that appears on the browser tab -->

</head>

<body>
    <!-- Contains all the visible content of the webpage -->

    <h1>Welcome to My Page</h1>
    <!-- This is a top-level heading, typically used for the main title of the page -->

    <p>This is a simple paragraph explaining the content of this page.</p>
    <!-- Defines a paragraph of text -->

    <a href="https://www.example.com">Visit Example.com</a>
    <!-- Creates a hyperlink that users can click to visit another page -->

</body>

</html>

具体功能的实现

滑动图片的实现

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <meta name="description" content="parallax one page" />
    <meta name="keywords" content="technology, optical, silicon, spectrum, application" />

    <!-- Font Google -->
    <link href="https://fonts.googleapis.com/css?family=Montserrat:400,500,600,700,800&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Raleway:400,500,600,700&display=swap" rel="stylesheet">

    <!-- Favicon -->
    <link rel="shortcut icon" href="assets/img/favicon.ico" type="image/x-icon" />
    <link rel="icon" href="assets/img/favicon.ico" type="image/x-icon" />

    <!-- Custom styles (optional) -->
    <link href="assets/css/plugins.css" rel="stylesheet" />
    <link href="assets/css/style.css" rel="stylesheet" />

    <style>
        /* Carousel Container */
        .multi-button-container {
            display: flex;
            overflow-x: auto;
            white-space: nowrap;
            scroll-snap-type: x mandatory;
            gap: 50px;
            padding: 50px;
        }

        /* Carousel Item */
        .multi-button-box {
            flex: 0 0 auto;
            width: 300px;
            height: 400px;
            background-size: cover;
            background-position: center;
            scroll-snap-align: start;
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            cursor: pointer;
            color: #FFFFFF;
            text-align: center;
            padding: 20px;
        }

        /* Hide scrollbar */
        .multi-button-container::-webkit-scrollbar {
            display: none;
        }

        /* Display Area for Text */
        .display-area {
            width: 90%;
            margin: 20px auto;
            padding: 20px;
            box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
            display: none;
        }

        /* Display Area Title */
        .display-area h2 {
            margin-top: 0;
        }

        /* Display Area Paragraph */
        .display-area p {
            margin: 10px 0;
        }

        /* Buttons for Scrolling */
        .scroll-button {
            background-color: #2f2e2e;
            color: #ffffff;
            border: none;
            padding: 10px;
            cursor: pointer;
            margin: 10px;
        }
    </style>
</head>

<body class="dsn-effect-scroll dsn-ajax" data-dsn-mousemove="true">

    <main class="main-root">
        <!-- Section for the Image Carousel -->
        <section class="our-work section-margin">
            <div class="container">
                <div class="one-title">
                    <div class="title-sub-container">
                        <p class="title-sub">Applications</p>
                    </div>
                    <h2 class="title-main">应用领域</h2>
                    <!-- Scroll Buttons -->
                    <button class="scroll-button" onclick="scrollContainer(-300)">上一个</button>
                    <button class="scroll-button" onclick="scrollContainer(300)">下一个</button>
                </div>
            </div>

            <!-- Image Carousel -->
            <div class="multi-button-container">
                <div class="multi-button-box" style="background-image: url('https://images.unsplash.com/photo-1725984509121-926215743c5e?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxmZWF0dXJlZC1waG90b3MtZmVlZHwzfHx8ZW58MHx8fHx8');" onclick="showContent('智能穿戴', 'Description for 智能穿戴...')">
                    <h3>智能穿戴</h3>
                </div>

                <div class="multi-button-box" style="background-image: url('https://images.unsplash.com/photo-1725984509121-926215743c5e?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxmZWF0dXJlZC1waG90b3MtZmVlZHwzfHx8ZW58MHx8fHx8');" onclick="showContent('化工制药', 'Description for 化工制药...')">
                    <h3>化工制药</h3>
                </div>

                <div class="multi-button-box" style="background-image: url('https://images.unsplash.com/photo-1725984509121-926215743c5e?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxmZWF0dXJlZC1waG90b3MtZmVlZHwzfHx8ZW58MHx8fHx8');" onclick="showContent('高端医疗', 'Description for 高端医疗...')">
                    <h3>高端医疗</h3>
                </div>
                <div class="multi-button-box" style="background-image: url('https://images.unsplash.com/photo-1725984509121-926215743c5e?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxmZWF0dXJlZC1waG90b3MtZmVlZHwzfHx8ZW58MHx8fHx8');" onclick="showContent('智能穿戴', 'Description for 智能穿戴...')">
                    <h3>智能穿戴</h3>
                </div>

                <div class="multi-button-box" style="background-image: url('https://images.unsplash.com/photo-1725984509121-926215743c5e?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxmZWF0dXJlZC1waG90b3MtZmVlZHwzfHx8ZW58MHx8fHx8');" onclick="showContent('化工制药', 'Description for 化工制药...')">
                    <h3>化工制药</h3>
                </div>

                <div class="multi-button-box" style="background-image: url('https://images.unsplash.com/photo-1725984509121-926215743c5e?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxmZWF0dXJlZC1waG90b3MtZmVlZHwzfHx8ZW58MHx8fHx8');" onclick="showContent('高端医疗', 'Description for 高端医疗...')">
                    <h3>高端医疗</h3>
                </div>
                <div class="multi-button-box" style="background-image: url('https://images.unsplash.com/photo-1725984509121-926215743c5e?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxmZWF0dXJlZC1waG90b3MtZmVlZHwzfHx8ZW58MHx8fHx8');" onclick="showContent('智能穿戴', 'Description for 智能穿戴...')">
                    <h3>智能穿戴</h3>
                </div>

                <div class="multi-button-box" style="background-image: url('https://images.unsplash.com/photo-1725984509121-926215743c5e?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxmZWF0dXJlZC1waG90b3MtZmVlZHwzfHx8ZW58MHx8fHx8');" onclick="showContent('化工制药', 'Description for 化工制药...')">
                    <h3>化工制药</h3>
                </div>

                <div class="multi-button-box" style="background-image: url('https://images.unsplash.com/photo-1725984509121-926215743c5e?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxmZWF0dXJlZC1waG90b3MtZmVlZHwzfHx8ZW58MHx8fHx8');" onclick="showContent('高端医疗', 'Description for 高端医疗...')">
                    <h3>高端医疗</h3>
                </div>


                <!-- Add more boxes as needed -->
            </div>

            <!-- Text Display Area -->
            <div class="container">
                <div id="display-area" class="display-area">
                    <h2 id="display-title"></h2>
                    <p id="display-content"></p>
                </div>
            </div>
        </section>
    </main>

    <!-- Optional JavaScript -->
    <script src="assets/js/jquery-3.1.1.min.js"></script>
    <script src="assets/js/plugins.js"></script>
    <script src="assets/js/dsn-grid.js"></script>
    <script src="assets/js/custom.js"></script>

    <script>
        // Function to display content when an image is clicked
        function showContent(title, content) {
            var displayArea = document.getElementById('display-area');
            document.getElementById('display-title').innerText = title;
            document.getElementById('display-content').innerHTML = content;
            displayArea.style.display = 'block';
        }

        // Function to scroll the image container
        function scrollContainer(distance) {
            document.querySelector('.multi-button-container').scrollBy({ left: distance, behavior: 'smooth' });
        }
    </script>
</body>
</html>

在手机端和电脑端显示不同的图片

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<style> 
    /* Default: Show the desktop image, hide the mobile image */
.desktop-img {
    display: block;
}
.mobile-img {
    display: none;
}
/* When screen width is less than or equal to 768px, show the mobile image, hide the desktop image */
@media (max-width: 1000px) {
    .desktop-img {
        display: none;
    }
    .mobile-img {
        display: block;
    }
}
</style>
</head>
<body>
    <div class="inner-img" data-dsn-grid="move-up">
        <!-- Desktop Image -->
        <img class="desktop-img" src="https://img-home.csdnimg.cn/images/20201124032511.png" alt="">
        <!-- Mobile Image -->
        <img class="mobile-img" src="https://profile-avatar.csdnimg.cn/895333eaf40542089c36e16ba65dce84_qq_41685627.jpg!1" alt="">
    </div>
</body>
</html>

手机端效果
手机端效果
电脑端效果电脑端效果

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部