批改状态:未批改
老师批语:
下面部分是CSS样式表
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>通用布局之双飞翼</title> <link rel="stylesheet" href="style.css"> </head> <body> <!-- 头部 --> <div class="header"> <div class="content"> <ul class="nav"> <li class="item"><a href="">首页</a></li> <li class="item"><a href="">视频教程</a></li> <li class="item"><a href="">社区问答</a></li> <li class="item"><a href="">编程词曲</a></li> <li class="item"><a href="">手册下载</a></li> <li class="item"><a href="">菜鸟学堂</a></li> </ul> </div> </div> <!-- 主体 --> <div class="container"> <!-- 创建双飞翼使用的DOM结构 --> <!-- 必须先创建中间主体区块,确保它优先被渲染出来 --> <!-- 中间内容区需要创建一个父级容器进行包裹 --> <div class="wrap"> <!-- 最终要展示的内容必须写在main区块中 --> <div class="main">主体内容区</div> </div> <!-- 左侧 --> <div class="left">左侧</div> <!-- 右侧 --> <div class="right">右侧</div> </div> <!-- 底部 --> <div class="footer"> <div class="content"> <p> <a href="">© PHP中文网:独家原创,永久免费的在线php视频教程,php技术学习阵地!</a> | <a href="">028-9090960</a> | <a href="">皖B2-20150071-9</a> </p> </div> </div> </body> </html>
点击 "运行实例" 按钮查看在线实例
.header {
/* 通常宽度默认为100% */
width: 100%;
/* 参考色块,上线时应该删除或替换 */
background-color: lightgray;
}
.header .content {
/* 头部内容区,应该居中显示,所有要有宽度 */
width: 1000px;
height: 60px;
/* 参考色块 */
background-color: lightgreen;
/* 上下外边距为0,左右自动居中 */
margin: 0 auto;
/* margin: 0 auto的等价语句,注意上右下左的顺序 */
margin-top: 0;
margin-right: auto;
margin-bottom: 0;
margin-left: auto;
/* 因为上下相等,左右也相等,所以可以简写为: margin: 0 auto; */
}
.header .content .nav {
/* 清空导航UL元素的默认样式 */
margin: 0;
padding: 0;
}
.header .content .nav .item {
list-style-type: none;
}
.header .content .nav .item a {
/* 一定要将浮动设置到链接标签<a>上面,否则无法实现导航区的点击与高亮 */
float: left;
/* 设置最小宽度与最小高宽,以适应导航文本的变化 */
min-width: 80px;
min-height: 60px;
/* 设置行高与头部区块等高,使导航文本可以垂直居中显示 */
line-height: 60px;
color: #444;
/* 将导航文本设置为系统根字体大小的1.2倍 */
font-size: 1.2rem;
/* 设置民航文本的左右内边距,使导航文本不要挨的太紧 */
padding: 0 15px;
/* 去掉链接标签默认的下划线 */
text-decoration: none;
/* 让导航文本在每一个小区块中居中显示 */
text-align: center;
}
.header .content .nav .item a:hover {
/* 当鼠标移入到导航链接上时改变背景色与文本前景色,实现当前导航高亮功能 */
border-radius: 20px;
background-color: #444;
color: white;
}
/*使用双飞翼布局实现主体部分*/
/*第一步:主体容器设置总宽度,并水平居中*/
.container {
width: 1000px;
min-height: 600px;
margin: 5px auto;
background-color: lightgray; /*参考色块*/
}
/*第二步:左右二侧固定宽度,中间区块自适应*/
/*中间区块宽度设置在它的容器wrap中*/
.wrap {
width: inherit; /*继承父级区块container宽度*/
min-height: inherit;
background-color: cyan;
}
/*设置左右区块的宽度和高度(因为无内容,所以设置了最小高度),并设置参考色块*/
.left {
width: 200px;
min-height: 600px;
background-color: yellow;
}
.right {
width: 200px;
min-height: 600px;
background-color: lightcoral;
}
/*第三步:将中间,左,右区块全部浮动*/
/*因中间区块宽度100%,所以左右会被挤压到下面*/
.wrap, .left, .right {
float: left;
}
/*第四步:将left和right拉回到他们正确的位置上*/
/*通过设置区块的负外边距的方式,实现向反方向移动区块*/
.left {
margin-left: -100%;
}
.right {
margin-left: -200px;
}
/*现在还有最后一个问题,中间内容区块main没有显示出来*/
/*第五步:将中间的内容区块main显示出来*/
.main {
padding-left: 200px;
padding-right: 200px;
}
/*底部与头部的基本样式 类似*/
.footer {
width: 100%;
background-color: lightgray;
}
.footer .content {
width: 1000px;
height: 50px;
background-color: lightblue;
margin: 0 auto;
}
.footer .content p {
text-align: center;
line-height: 50px;
}
.footer .content a {
text-decoration: none;
color: #777;
}
/*鼠标移入时显示下划线并加深字体前景色*/
.footer .content a:hover {
text-decoration: underline;
color: #444;
}点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号