博主信息
博文 9
粉丝 0
评论 0
访问量 7952
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
CSS布局原理与实现
橙汁的博客
原创
786人浏览过
  1. 实例演示如何消除子元素浮动造成父元素高度折叠的影响

    clipboard.png

    实例

    <!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>Document</title>
        <style>
            #div1 {
                width: 300px;
                border: 4px dashed #f90;
                /* display: inline-block; */
                overflow: hidden;
            }
            
            #div2 {
                width: 300px;
                height: 400px;
                background-color: aqua;
                float: left;
            }
        </style>
    </head>
    
    <body>
        <div id="div1">
            <div id="div2"></div>
        </div>
    </body>
    
    </html>

    运行实例 »

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

    2. 实例演示三列布局的实现原理( 绝对定位实现, 浮动定位实现)

    4632.jpg

    实例绝对定位

    <!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>
            .header,
            .footer {
                width: 1000px;
                height: 50px;
                background-color: aliceblue;
                margin: 0 auto;
            }
            
            .main {
                width: 1000px;
                background-color: aquamarine;
                margin: 10px auto;
                
                position: relative;
            }
            .left{
                width:200px;
                min-height: 800px;
                background-color: bisque;
    
                position: absolute;
                left:0;
                top:0;
            }
            .content{
                min-height: 800px;
                background-color:lawngreen;
    
                margin: 0 200px;
            }
            .right{
                width:200px;
                min-height: 800px;
                background-color:lightcoral;
    
                position: absolute;
                right:0;
                top:0;
            }
        </style>
    </head>
    
    <body>
        <div class="header">header</div>
        <div class="main">
            <div class="left">left</div>
            <div class="content">content</div>
            <div class="right">right</div>
        </div>
        <div class="footer">footer</div>
    </body>
    
    </html>

    运行实例 »

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

实例浮动定位

<!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>
        .header,
        .footer {
            width: 1000px;
            height: 50px;
            background-color: aliceblue;
            margin: 0 auto;
        }
        
        .main {
            width: 1000px;
            background-color: aquamarine;
            margin: 10px auto;
            overflow: hidden;
        }
        
        .left {
            width: 200px;
            min-height: 800px;
            background-color: bisque;
            float: left;
        }
        
        .content {
            width: 600px;
            min-height: 800px;
            background-color: lawngreen;
            float: left;
        }
        
        .right {
            width: 200px;
            min-height: 800px;
            background-color: lightcoral;
            float: right;
        }
    </style>
</head>

<body>
    <div class="header">header</div>
    <div class="main">
        <div class="left">left</div>
        <div class="content">content</div>
        <div class="right">right</div>
    </div>
    <div class="footer">footer</div>
</body>

</html>

运行实例 »

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


批改状态:合格

老师批语:三列布局是一切布局的集大成者
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系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+教程免费学