前端知识点

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

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>

具体功能的实现

滑动图片的实现

python 复制代码
<!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>

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

python 复制代码
<!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>

手机端效果

电脑端效果

相关推荐
前端拾光者28 分钟前
利用D3.js实现数据可视化的简单示例
开发语言·javascript·信息可视化
Json_181790144801 小时前
电商拍立淘按图搜索API接口系列,文档说明参考
前端·数据库
风尚云网1 小时前
风尚云网前端学习:一个简易前端新手友好的HTML5页面布局与样式设计
前端·css·学习·html·html5·风尚云网
木子02041 小时前
前端VUE项目启动方式
前端·javascript·vue.js
GISer_Jing1 小时前
React核心功能详解(一)
前端·react.js·前端框架
捂月1 小时前
Spring Boot 深度解析:快速构建高效、现代化的 Web 应用程序
前端·spring boot·后端
深度混淆1 小时前
实用功能,觊觎(Edge)浏览器的内置截(长)图功能
前端·edge
Smartdaili China1 小时前
如何在 Microsoft Edge 中设置代理: 快速而简单的方法
前端·爬虫·安全·microsoft·edge·社交·动态住宅代理
秦老师Q1 小时前
「Chromeg谷歌浏览器/Edge浏览器」篡改猴Tempermongkey插件的安装与使用
前端·chrome·edge
滴水可藏海1 小时前
Chrome离线安装包下载
前端·chrome