LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

零基础网页开发21(配套CSS代码)

admin
2025年7月30日 9:40 本文热度 104
接上篇,给出了HTML网页代码后,我们已经实现了一个静态的网页demo。现在我们配合完整的CSS样式表,使其显示为具有视觉吸引力的网站。

我将整个CSS样式表放在一个代码块中,并在每部分添加注释进行解释。

注意:CSS中的选择器用于指定要样式化的HTML元素。样式规则由属性和值组成。

以下是逐段解释:(可直接复制,配合HTML代码使用

/* 以下是完整的CSS样式表解析 */
/* 全局重置:清除所有元素的内外边距 */*{    padding0;    margin0;}
/* 页眉样式 */header{    background-colorrgba(35,28,26,0.8); /* 深色半透明背景 */    height:80px/* 固定高度 */    width:100%/* 全宽 */    position: fixed; /* 固定定位(始终在顶部) */}
/* 标题基础样式 */h1{    color: white; /* 白色文字 */}
/* 导航菜单定位 */header ul{    position: absolute; /* 绝对定位 */    right:5vw/* 距离右边5%视口宽度 */    top:0/* 顶部对齐 */    line-height80px/* 垂直居中 */}
/* 网站标题特殊效果 */h1{    position:absolute; /* 绝对定位 */    left:120px/* 左侧偏移 */    top:0/* 顶部对齐 */    line-height80px/* 垂直居中 */    background-imageurl(image/司绿.jpg); /* 用图片作为背景 */    background-repeat: no-repeat; /* 禁止平铺 */    background-position: center; /* 居中显示 */    width210px/* 固定宽度 */    text-indent: -9999px/* 隐藏文字(仅显示背景图) */}
/* 导航菜单项样式 */header li{    display: inline; /* 水平排列 */    margin-right4vw/* 右侧间距 */}header a{    color:white; /* 白色链接 */    text-decoration:none; /* 无下划线 */}header a:hover{    text-decoration: underline; /* 鼠标悬停显示下划线 */}
/* 最新动态区域样式 */.news{    background-color: antiquewhite; /* 备用背景色 */    color: white; /* 白色文字 */    height95vh/* 高度占95%视口 */    background-imageurl(image/思蓝.jpg); /* 背景图片 */    background-repeat: no-repeat; /* 禁止平铺 */    background-size: cover; /* 覆盖整个区域 */    background-position: center; /* 居中显示 */    display: flex; /* 弹性布局 */    flex-direction: column; /* 垂直排列 */    align-items: center; /* 水平居中 */    justify-content: center; /* 垂直居中 */}.news h2{    font-size60px/* 大标题 */    margin-top:60px/* 顶部间距 */}.news p{    color#fef7e6/* 浅米色文字 */    font-size18px    margin:25px 0/* 上下间距 */}.news a{    color:white;     text-decoration: none;     border1px solid #acacac/* 边框 */    padding10px 20px/* 内边距 */    border-radius5px/* 圆角 */}
/* 标语区域样式 */.slogan{    background-color#485652/* 深绿色背景 */    color: white;     height250px/* 固定高度 */    display:flex;     justify-content: center; /* 水平居中 */    align-items: center; /* 垂直居中 */    font-size20px    line-height1.8em/* 行高 */}
/* 页脚样式 */footer{    background-color#000000    color#b7b7b7/* 浅灰色文字 */    height60px/* 固定高度 */    display:flex;     justify-content: center;     align-items: center;     font-size14px}
/* 商店区域布局 */.shop{    display: flex; /* 弹性盒子布局 */}.shop img{    width50%/* 图片占一半宽度 */}
/* 商店信息区域 */.info{    width50%/* 占一半宽度 */    background-color: white;     display: flex;     flex-direction: column; /* 垂直排列 */    align-items: center;     justify-content: center; }.info h2{    font-size40px    margin-bottom30px/* 底部间距 */}.info p{    text-align: center; /* 居中文本 */    line-height2em/* 2倍行高 */}
/* 产品展示区 */.product{    display: flex;     background-color#ede9db/* 米色背景 */    justify-content: space-between; /* 等间距分布 */    align-items: center;     padding100px 180px 80px/* 内边距:上 左右 下 */}.product div{    width300px/* 固定宽度 */    text-align: center; /* 居中内容 */}.product img{    width:100%/* 图片撑满容器 */    border-radius10px/* 圆角图片 */}.product h3{    font-size20px    margin20px 0/* 上下间距 */}.product p{    font-size14px    line-height1.6em/* 1.6倍行高 */}
/* 电子报订阅区 */.newsletter{    background-color#485652/* 深绿色背景 */    color: white;     padding60px 0/* 上下内边距 */    display: flex;     flex-direction: column;     align-items: center; }.newsletter p{    margin-bottom20px}
/* 表单元素样式 */.newsletter input,.newsletter button{    background-color: transparent; /* 透明背景 */    color: white;     border1px solid #949d9a/* 边框 */    padding10px    border-radius5px/* 圆角 */}.newsletter input{    width200px/* 固定宽度 */    margin-right15px/* 右侧间距 */}.newsletter button{    width80px    cursor: pointer; /* 手型光标 */}
/* 输入框特殊状态 */input::placeholder{    color#dddddd/* 占位符颜色 */}input:focus{    outline: none; /* 移除默认轮廓 */    border-color#e0e9a3/* 聚焦时边框颜色 */}
/* 移动端菜单默认隐藏 */.menu{    display: none; }
/* 响应式设计:屏幕宽度≤768px时触发的样式 */@media screen and (max-width768px) {    /* 隐藏桌面导航 */    header ul{        display: none;    }
    /* 居中标题 */    header h1 {        left:50%;        transform:translateX(-50%); /* 水平居中 */    }
    /* 调整新闻标题大小 */    .news h2{        font-size40px;    }
    /* 显示移动菜单按钮 */    .menu{        display: block;         background-color: transparent;         color: white;         font-size35px        position: absolute;         top:15px        left:20px        border:none;         cursor:pointer; /* 手型光标 */    }
    /* 调整商店区域为垂直布局 */    .shop{        flex-direction: column;     }    .shop img{        width100%/* 图片全宽 */    }
    /* 调整信息区域 */    .info{        width100%        padding40px 0/* 增加上下内边距 */    }    .info h2{        font-size30px/* 缩小标题 */    }
    /* 产品区域改为垂直排列 */    .product{        flex-direction: column;         padding60px 0/* 调整内边距 */    }    .product div{        margin-bottom30px/* 产品项间距 */    }}

样式表整体解析:

1. 设计特点:

◦ 全屏背景:.news区域使用全屏背景图

◦ 固定导航position: fixed实现滚动时导航栏始终置顶

◦ 隐藏式文字:text-indent: -9999px隐藏h1文字(仅显示背景图)

◦ 响应式设计@media查询实现移动端适配

2. 布局系统:

◦ 使用 Flexbox 布局.shop.product.newsletter

◦ 使用 视口单位(vhvw)实现响应式尺寸

◦ 绝对定位用于导航菜单(position: absolute

3. 交互效果:

◦ 链接悬停效果(text-decoration: underline

◦ 输入框聚焦效果(border-color: #e0e9a3

◦ 按钮悬停指示(cursor: pointer

4. 移动端优化:

◦ 768px以下隐藏桌面导航

◦ 显示汉堡菜单按钮(☰)

◦ 垂直排列产品项

◦ 全宽图片展示

5. 视觉细节:

◦ 半透明导航栏(rgba(35,28,26,0.8))

◦ 圆角设计(border-radius: 10px)

◦ 间距系统(使用margin和padding控制元素间距)

这个样式表与HTML配合,创建了一个具有文化氛围的响应式网站。

桌面端显示专业布局,移动端自动调整为更适合小屏幕的垂直布局。

本文由于给出了整个CSS样式表,所以此篇文章的篇幅较长,但是非常实用,结合上篇给出的HTML代码,直接复制就能上手用。千万不要被文章的篇幅所吓倒~


阅读原文:https://mp.weixin.qq.com/s/TKKHbInbtcoisivAO4tOww


该文章在 2025/7/30 9:40:49 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2025 ClickSun All Rights Reserved