前端知识点

下面是一个最基本的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>

手机端效果

电脑端效果

相关推荐
ct97826 分钟前
vue2 + vue3差异点
前端·javascript·vue.js
小徐_233336 分钟前
程序员每天盯屏 10 小时,我开始认真研究“专业编程屏”这件事
前端
悟空瞎说1 小时前
Git 协作工作流详解:从个人单打独斗到规模化团队协同
前端·git
颜进强1 小时前
20-Spec-Kit Tasks 是怎么把技术方案拆成可执行任务的?
前端·后端·ai编程
程序员鱼皮1 小时前
Cursor 零基础实战教程,夯爆了!带你速通 6 大核心能力
前端·后端·ai编程
颜进强1 小时前
14-Spec-Kit、SDD 和 OpenSpec 到底有什么区别?其实核心思想都一样:先写清楚,再让 AI 干活
前端·后端·ai编程
颜进强1 小时前
16-Spec-Kit 是什么?先从整体流程机制讲起
前端·后端·ai编程
悟空瞎说1 小时前
QML 集成 WebView 开发桌面内嵌浏览器实战
前端
八目蛛1 小时前
八目蛛网络(免费工具网站导航)
css·vue.js·开源·vue3·html5·ai编程
Delicate1 小时前
揭开JS深拷贝的底裤:从递归到循环引用的终极解法
javascript