博主信息
博文 14
粉丝 0
评论 0
访问量 7878
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
清除浮动的各种方式以及网站常用布局学习。2019年5月4日22点55分
蔡小逗
原创
1144人浏览过

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>双飞翼布局</title>
   
</head>
<style>
/*头部内容区*/
.header .content {
    width: 1000px;
    height: 50px;
    background-color: #eee;
    /* 上下外边距为0,左右自动居中 */
    margin: 0 auto;
}

/*头部导航,清楚默认样式*/
.header .content .nav {
    margin:0;padding:0;
}

.header .content .nav .item {
    list-style: none;
}

/*头部导航中的链接样式: 重点*/
.header .content .nav .item a {
    float: left;
    min-width: 80px;
    min-height: 50px;
    line-height: 50px;
    color: white;
    padding: 0 12px;
    text-decoration: none;
    text-align: center;
}

.header .content .nav .item a:hover {
    background-color: red;
    font-size: 1.1rem;
}
/** 头部样式结束 **/




/**主体样式开始***/


/* 双飞翼布局 */

/* 主体容器水平居中 */
.container {
    width: 800px;
    margin: 5px auto;
    background-color: lightpink;
    overflow: hidden;
}
.wrap, .left, .right {
    float: left;
}
.wrap {
    /* 继承父级区块container宽度*/
    width: inherit;
    min-height: 800px;
    background-color: cyan;
}

.left {
    width: 200px;
    min-height: 800px;
    background-color: lightcoral;
    margin-left: -100%;
}
/* 右边栏样式 */
.right {
    width: 200px;
    min-height: 800px;
    background-color: lightseagreen;
    margin-left: -200px;
}

.main {
    padding-left: 200px;
    padding-right: 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>
<body>
    <!-- 头部 -->
    <div class="header">
        <div class="content">
            <ul class="nav">
                <li class="item"><a href="">Home</a></li>
                <li class="item"><a href="">NEWS</a></li>
                <li class="item"><a href="">Product</a></li>
                <li class="item"><a href="">About Us</a></li>
            </ul>
        </div>
    </div>

    <!-- 中间主体 -->
    <div class="container">
        <!-- 确保中间主体区块,优先被渲染出来 -->    
        <div class="wrap">
           
            <div class="main">中间区域</div>
        </div>

        <!--左侧 -->
        <div class="left">左侧</div>

        <!--右侧 -->
        <div class="right">右侧</div>

    </div>

    <!-- 底部 -->
    <div class="footer">
        <div class="content">
            <p>
                <a href="">© 个人所有</a>  | 
                  <a href="">网站通用布局-双飞翼</a> 
            </p>
            
        </div>
    </div>
</body>
</html>

运行实例 »

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

双飞翼布局利用浮动和内外边距巧妙地把网页分为左中右,并且可以灵活增删,适用于各种网站布局

清除浮动常用方法

创建一个类用来清除浮动

.clear {

    clear: both;

}

这个方案简单粗暴,但会多增加一个dom元素

 父元素添加一个伪元素,专用来清浮动

.box1::after {

    content: '';

    display: block;

    /*考虑到兼容性, 加个高度0,上个双保险,大多情况下可省略*/

    height: 0;*/

   clear: both;

}

父元素添加overflower,专用来清浮动 

    overflow: hidden;

最常用并且最简单的就是最后一种方法 overflow: hidden;


批改状态:未批改

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学