Blogger Information
Blog 38
fans 1
comment 0
visits 24242
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
4月29日作业网页圣杯布局
鲨鱼辣椒的博客
Original
619 people have browsed it

HTML+CSS做一个网页圣杯布局

代码如下:

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>圣杯布局</title>
    <style>
        /******************* 头部样式开始 ******************/

        .header {
            /* 参考色块,上线时应该删除或替换 */
            background-color: lightgray;
        }

        /*头部内容区*/
        .header .content {
            /* 头部内容区,应该居中显示,所有要有宽度 */
            width: 1000px;
            height: 60px;
            /* 参考色块 */
            background-color: black;
            /* 上下外边距为0,左右自动居中 */
            /* 因为上下相等,左右也相等,所以可以简写为: margin: 0 auto; */
            margin: 0 auto;

        }

        /*头部内容区中的导航*/
        .header .content .nav {
            /* 清空导航UL元素的默认样式 */
            margin-top: 0;
            margin-bottom: 0;
            padding-left: 0;
            /*如果记不住究竟要清空哪些,可以粗暴点: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: white;

            /* 设置民航文本的左右内边距,使导航文本不要挨的太紧 */
            padding: 0 15px;
            /* 去掉链接标签默认的下划线 */
            text-decoration: none;
            /* 让导航文本在每一个小区块中居中显示 */
            text-align: center;
        }

        .header .content .nav .item a:hover {
            /* 当鼠标移入到导航链接上时改变背景色与文本前景色,实现当前导航高亮功能 */
            background-color: red;
            /* 将导航文本设置为系统根字体大小的1.2倍 */
            font-size: 1.1rem;
        }
        /******************* 头部样式结束 ******************/
        /*1. 主体容器设置的宽度与中间区块相同,并水平居中*/
        .container{
            width: 600px;
            margin: 5px auto;
            background-color: lightgray;
            border: 2px solid black;
            overflow: hidden;
        }
        /*2. 左,右二侧固定宽度,中间区块继承父级container宽度*/
        .main{
            width: inherit;
            min-height: 800px;
            background-color: lightcyan;
        }

        .left{
            width: 200px;
            min-height: 800px;
            background-color: slateblue;
        }

        .container .left .nav .item{
            list-style-type: none;
        }
        .container .left .nav .item a{
            /* 一定要将浮动设置到链接标签<a>上面,否则无法实现导航区的点击与高亮 */
            min-width: 80px;
            min-height: 60px;
            line-height: 60px;
            color: wheat;
            padding: 0 15px;
            text-decoration: none;
            text-align: center;
        }

        .container .left .nav .item a:hover{
            color: red;
            font-size: 1.1rem ;
        }

        .right{
            width: 200px;
            min-height: 800px;
            background-color: aqua;
        }

        .main, .left, .right{
            float: left;
        }

        .left{
            margin-left: -100%;
        }

        .right{
            margin-left: -200px;
        }

        .container {
            padding-left: 200px;
            padding-right: 200px;
        }

        .left {
            position: relative;
            left: -200px;
        }

        .right {
            position: relative;
            left: 200px;
        }


        /* 底部与头部的基本样式类似 */
        .footer {
            background-color: lightgray;
        }

        .footer .content {
            width: 1000px;
            height: 60px;
            background-color: #444;
            margin: 0 auto;
        }
        .footer .content p {
            text-align: center;
            line-height: 60px;
        }

        .footer .content  a {
            text-decoration: none;
            color: lightgrey;
        }

        /* 鼠标移入时显示下划线并加深字体前景色 */
        .footer .content  a:hover {
            color: white;
        }
    </style>
</head>
<body>
<!--header头部-->
<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>
        </ul>
    </div>
</div>

<!--container中间主题-->
<div class="container">
    <!-- 1. 中间内容区块 -->
    <!-- 与双飞翼相比, DOM结构更简洁, 不需要为main创建父级容器 -->
    <div class="main">主体内容块</div>

    <!--2. left左侧边栏区块-->
    <div class="left">
        <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>
        </ul>
    </div>

    <!--3. right右侧边栏区块-->
    <div class="right">右侧</div>

</div>

<!--footer底部页脚-->
<div class="footer">
    <div class="content">
        <p>
            <a href="">© PHP中文网版权所有</a>  | 
            <a href="">0551-88889999</a>  | 
            <a href="">皖ICP2016098801-1</a>
        </p>
    </div>
</div>

</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post