博主信息
博文 10
粉丝 0
评论 0
访问量 6329
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
实例演示消除子元素浮动及三列布局 -- 2019年09月04日
阿来的blog
原创
855人浏览过

1.消除子元素浮动造成父元素高度折叠的影响。


实例

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>消除子元素浮动造成父元素高度折叠的影响</title>
    <style>
        .box1 {
            width: 300px;
            border: 5px solid red;
            /* float: left; */
            overflow: hidden;
        }
        
        .box2 {
            width: 200px;
            height: 300px;
            background-color: blue;
            float: left;
        }
        /* .clear{
            clear:both;
        } */
    </style>
</head>

<body>
    <div class="box1">
        <div class="box2">
            消除子元素浮动造成父元素高度折叠的影响
        </div>
    </div>
</body>

</html>

运行实例 »

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

1111111.png


2.三列布局的实现原理

2.1绝对定位实现


实例

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>绝对定位实现三列布局</title>
    <style>
        .box {
            width: 1000px;
            margin: 0 auto;
        }
        
        .head {
            height: 50px;
            background-color: lightgreen;
        }
        
        .index {
            margin: 5px auto;
            min-height: 800px;
            position: relative;
        }
        
        .foot {
            height: 50px;
            background-color: lightseagreen;
        }
        
        .indexl {
            width: 200px;
            background-color: lightcoral;
            min-height: 800px;
            position: absolute;
            left: 0;
            top: 0;
        }
        
        .indexc {
            background-color: green;
            min-height: 800px;
            width: 590px;
            position: absolute;
            margin-left: 205px;
        }
        
        .indexr {
            width: 200px;
            background-color: palevioletred;
            min-height: 800px;
            position: absolute;
            right: 0;
            top: 0;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="head">头部</div>
        <div class="index">
            <div class="indexl">左</div>
            <div class="indexc">中</div>
            <div class="indexr">右</div>
        </div>
        <div class="foot">尾部</div>
    </div>
</body>

</html>

运行实例 »

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

12.png

2.2浮动定位实现


实例

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>浮动定位实现三列布局</title>
    <style>
        .box {
            width: 1000px;
            margin: 0 auto;
            overflow: hidden;
        }
        
        .head {
            height: 50px;
            background-color: lightgreen;
        }
        
        .index {
            margin: 5px auto;
            min-height: 800px;
        }
        
        .foot {
            height: 50px;
            background-color: lightseagreen;
        }
        
        .indexl {
            width: 200px;
            background-color: red;
            min-height: 800px;
            float: left;
            left: 0;
            top: 0;
        }
        
        .indexc {
            width: 600px;
            background-color: green;
            min-height: 800px;
            float: left;
        }
        
        .indexr {
            width: 200px;
            background-color: palevioletred;
            min-height: 800px;
            float: right;
            left: 0;
            top: 0;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="head">头部</div>
        <div class="index">
            <div class="indexl">左</div>
            <div class="indexc">中</div>
            <div class="indexr">右</div>
        </div>
        <div class="foot">尾部</div>
    </div>
</body>

</html>

运行实例 »

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

QQ图片20190904235321.png


批改状态:合格

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

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

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