HTML+CSS新技能:快速打造响应式步骤条,秒变网页设计达人!

简介: HTML+CSS新技能:快速打造响应式步骤条,秒变网页设计达人!

效果



完整代码



HTML部分

<div class="progress-container">
        <div class="progress-bar">
            <div class="progress" id="progress"></div>
            <div class="step active">1<span class="step-label">步骤 1</span></div>
            <div class="step">2<span class="step-label">步骤 2</span></div>
            <div class="step">3<span class="step-label">步骤 3</span></div>
            <div class="step">4<span class="step-label">步骤 4</span></div>
        </div>
        <button id="prevBtn" onclick="changeStep(-1)" disabled>上一步</button>
        <button id="nextBtn" onclick="changeStep(1)">下一步</button>
    </div>

CSS部分

body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
        }
        .progress-container {
            width: 100%;
            max-width: 600px;
            padding: 20px;
        }
        .progress-bar {
            display: flex;
            justify-content: space-between;
            align-items: center;
            position: relative;
            margin-bottom: 30px;
        }
        .progress-bar::before {
            content: '';
            position: absolute;
            top: 50%;
            left: 0;
            transform: translateY(-50%);
            height: 4px;
            width: 100%;
            background-color: #ddd;
            z-index: 1;
        }
        .progress {
            position: absolute;
            top: 50%;
            left: 0;
            transform: translateY(-50%);
            height: 4px;
            width: 0;
            background-color: #4CAF50;
            z-index: 2;
            transition: width 0.5s ease;
        }
        .step {
            width: 30px;
            height: 30px;
            background-color: #fff;
            border: 3px solid #ddd;
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
            font-weight: bold;
            color: #999;
            z-index: 3;
            transition: all 0.3s ease;
        }
        .step.active {
            border-color: #4CAF50;
            color: #4CAF50;
        }
        .step-label {
            position: absolute;
            top: 100%;
            left: 50%;
            transform: translateX(-50%);
            text-align: center;
            font-size: 14px;
            color: #666;
            margin-top: 8px;
        }
        button {
            padding: 10px 20px;
            font-size: 16px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }
        button:hover {
            background-color: #45a049;
        }
        button:disabled {
            background-color: #ddd;
            cursor: not-allowed;
        }

JS

<script>
        let currentStep = 1;
        const totalSteps = 4;
        const progress = document.getElementById('progress');
        const prevBtn = document.getElementById('prevBtn');
        const nextBtn = document.getElementById('nextBtn');
        const steps = document.querySelectorAll('.step');
        function updateButtons() {
            prevBtn.disabled = currentStep === 1;
            nextBtn.disabled = currentStep === totalSteps;
            nextBtn.textContent = currentStep === totalSteps ? '完成' : '下一步';
        }
        function updateProgressBar() {
            const percent = ((currentStep - 1) / (totalSteps - 1)) * 100;
            progress.style.width = `${percent}%`;
        }
        function updateSteps() {
            steps.forEach((step, index) => {
                if (index < currentStep) {
                    step.classList.add('active');
                } else {
                    step.classList.remove('active');
                }
            });
        }
        function changeStep(n) {
            currentStep += n;
            if (currentStep < 1) currentStep = 1;
            if (currentStep > totalSteps) currentStep = totalSteps;
            updateButtons();
            updateProgressBar();
            updateSteps();
        }
        updateButtons();
    </script>
相关文章
|
17天前
一个好看的小时钟html+js+css源码
一个好看的小时钟html+js+css源码
87 24
|
25天前
|
JavaScript
jquery和CSS3响应式轮播图插件jcSlider
jcSlider是一款jquery和CSS3响应式轮播图插件。jcSlider使用CSS3过渡动画,它可以和animate.css完美结合,生成60多种轮播图过渡动画效果。
|
2月前
|
前端开发 测试技术 定位技术
如何利用HTML和CSS构建企业级网站的全过程。从项目概述到页面结构设计,再到HTML结构搭建与CSS样式设计,最后实现具体页面并进行优化提升,全面覆盖了网站开发的关键步骤
本文深入介绍了如何利用HTML和CSS构建企业级网站的全过程。从项目概述到页面结构设计,再到HTML结构搭建与CSS样式设计,最后实现具体页面并进行优化提升,全面覆盖了网站开发的关键步骤。通过实例展示了主页、关于我们、产品展示、新闻动态及联系我们等页面的设计与实现,强调了合理布局、美观设计及用户体验的重要性。旨在为企业打造一个既专业又具吸引力的线上平台。
82 7
|
2月前
|
前端开发 JavaScript 搜索推荐
HTML与CSS在Web组件化中的核心作用及前端技术趋势
本文探讨了HTML与CSS在Web组件化中的核心作用及前端技术趋势。从结构定义、语义化到样式封装与布局控制,两者不仅提升了代码复用率和可维护性,还通过响应式设计、动态样式等技术增强了用户体验。面对兼容性、代码复杂度等挑战,文章提出了相应的解决策略,强调了持续创新的重要性,旨在构建高效、灵活的Web应用。
51 6
|
2月前
|
存储 移动开发 前端开发
高效的 HTML 与 CSS 编写技巧,涵盖语义化标签、文档结构优化、CSS 预处理、模块化设计、选择器优化、CSS 变量、媒体查询等内容
本文深入探讨了高效的 HTML 与 CSS 编写技巧,涵盖语义化标签、文档结构优化、CSS 预处理、模块化设计、选择器优化、CSS 变量、媒体查询等内容,旨在提升开发效率、网站性能和用户体验。
58 5
|
2月前
|
移动开发 JavaScript 前端开发
html table+css实现可编辑表格的示例代码
html table+css实现可编辑表格的示例代码
90 12
|
2月前
|
前端开发 JavaScript
用HTML CSS JS打造企业级官网 —— 源码直接可用
必看!用HTML+CSS+JS打造企业级官网-源码直接可用,文章代码仅用于学习,禁止用于商业
174 1
|
5月前
|
前端开发
2s 利用 HTML+css动画实现企业官网效果
2s 利用 HTML+css动画实现企业官网效果
HTML+CSS 实现通用的企业官网页面(记得收藏)
HTML+CSS 实现通用的企业官网页面(记得收藏)