Blogger Information
Blog 8
fans 0
comment 0
visits 4730
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
圣杯布局模式-2019年9月5号
zzc111的博客
Original
500 people have browsed it

圣杯布局模式

实例

<style>
        body {
            /* 清除外边距 */
            margin: 0;
        }
        /* 头部样式 */
        
        .header {
            /* 头部添加背景色 */
            background-color: black;
        }
        
        .header .content {
            /* 宽度 */
            width: 90%;
            /* 添加背景色 */
            background-color: black;
            /* 外边距上下0左右自动 */
            margin: 0 auto;
            height: 60px;
        }
        
        .header .content .nav {
            /* 清除外边距 */
            margin: 0;
            /* 清除内边距 */
            padding: 0;
        }
        
        .header .content .nav .item {
            /* 清除无序列表小黑点 */
            list-style: none;
        }
        
        .header .content .nav .item a {
            /* a标签左浮动 */
            float: left;
            /* 最小宽度 */
            min-width: 80px;
            /* 最小高度 */
            min-height: 60px;
            /* 文本水平居中 */
            text-align: center;
            /* 文本垂直居中 */
            line-height: 60px;
            /* 文字颜色 */
            color: white;
            /* a标签内边距 */
            padding: 0 15px;
            /* 去除a标签下划线 */
            text-decoration: none;
        }
        /* 鼠标移动放上效果 */
        
        .header .content .nav .item a:hover {
            background-color: red;
            /* 字体放大 */
            font-size: 1.1rem;
        }
        /* 主体样式 */
        
        .container {
            width: 90%;
            background-color: lightgray;
            margin: 5px auto;
            overflow: hidden;
        }
        /* 中间 */
        
        .slider {
            width: 100%;
            margin: 0 auto;
        }
        
        .slider img {
            width: 100%;
        }
        
        .main {
            width: 100%;
            background-color: lightblue;
            min-height: 800px;
            box-sizing: border-box;
            padding-left: 200px;
            padding-right: 200px;
            float: left;
        }
        /* 左侧 */
        
        .left {
            width: 200px;
            min-height: 800px;
            background-color: lightgreen;
            margin-left: -100%;
            float: left;
            border: 1px solid black;
        }
        /* 右侧 */
        
        .right {
            width: 200px;
            min-height: 800px;
            background-color: lightcoral;
            margin-left: -200px;
            float: left;
        }
        
        .footer {
            background-color: #444;
        }
        
        .footer .content {
            width: 90%;
            background-color: #444;
            margin: 0 auto;
            height: 60px;
        }
        
        .footer .content p {
            /* 文本水平居中 */
            text-align: center;
            /* 文本垂直居中 */
            line-height: 60px;
        }
        
        .footer .content p a {
            /* 文字颜色 */
            color: #999999;
            /* 去除a标签下划线 */
            text-decoration: none;
        }
        
        .footer .content p a:hover {
            background-color: white;
            /* 字体放大 */
            font-size: 1.1rem;
        }
        /* 左侧导航样式 */
        
        .left h1 {
            color: #555;
            font-size: 1.3rem;
            border-bottom: 1px solid #555555;
        }
        
        .left ul {
            list-style: none;
        }
        
        .left a {
            text-align: center;
            /* 文本垂直居中 */
            line-height: 30px;
            /* 文字颜色 */
            color: black;
            /* a标签内边距 */
            padding: 0 15px;
            /* 去除a标签下划线 */
            text-decoration: none;
        }
        
        .left ul li a:hover {
            background-color: red;
            /* 字体放大 */
            font-size: 1.1rem;
        }
    </style>
</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>
            </ul>
        </div>
    </div>


    <!-- 主体 -->
    <div class="container">
        <!-- 主体内容 -->
        <div class="main">
            <div class="slider">
                <img src="timg.jpg" alt="">
            </div>
        </div>
        <!-- 左侧 -->
        <div class="left">
            <h1>商品列表</h1>
            <ul>
                <li><a href="">我的商品</a></li>
                <li><a href="">我的商品</a></li>
                <li><a href="">我的商品</a></li>
                <li><a href="">我的商品</a></li>
                <li><a href="">我的商品</a></li>
            </ul>
        </div>
        <!-- 右侧 -->
        <div class="right"></div>
    </div>

    <!-- 底部 -->
    <div class="footer">
        <!-- 内容区 -->
        <div class="content">
            <p>
                <a href="">©个人版权所有</a> | 
                <a href="">0371-666xxx888</a> | 
                <a href="">豫ICP备66666-8888</a> | 
            </p>
        </div>
    </div>
</body>

</html>

运行实例 »

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

总结:

(1)中间部分需要根据浏览器宽度的变化而变化,所以要用100%,这里设左中右向左浮动,因为中间100%,左层和右层根本没有位置上去

(2)把左层margin负100后,发现left上去了,因为负到出窗口没位置了,只能往上挪

(3)按第二步这个方法,可以得出它只要挪动窗口宽度那么宽就能到最左边了,利用负边距,把左右栏定位

(4)但由于左右栏遮挡住了中间部分,于是采用相对定位方法,各自相对于自己把自己挪出去,得到最终结果


Correction status:qualified

Teacher's comments:将左右二栏移到正确的位置上, 有多种方式, 使用postion, margin, padding都可以实现
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