博主信息
博文 12
粉丝 1
评论 0
访问量 10518
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
9.4作业
lee的学习记录博客
原创
784人浏览过

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>Document</title>
    <style>
        .box1 {
            width: 150px;
            border: 5px solid rgb(40, 9, 211);
            overflow: hidden;
            /* 主要用来清浮动,消除子级浮动给父级元素高度折叠的影响 */
        }
        
        .box2 {
            width: 150px;
            height: 150px;
            background: rgb(5, 219, 41);
            float: left;
        }
    </style>
</head>

<body>
    <div class="box1">
        <div class="box2"></div>
    </div>
</body>

</html>

运行实例 »

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


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>Document</title>
    <style>
        .box {
            width: 800px;
            overflow: hidden;
            background: burlywood;
            margin: 0 auto
        }
        
        .nav {
            width: 800px;
            height: 50px;
            background: aquamarine;
            float: left;
        }
        
        .footer {
            width: 800px;
            height: 50px;
            background: rgb(207, 158, 21);
            float: left;
        }
        
        .main {
            width: 800px;
            min-height: 600px;
            float: left;
            background: rgb(31, 10, 223);
            position: relative;
        }
        
        .left {
            width: 200px;
            height: 600px;
            background: brown;
            position: absolute;
            left: 0;
            top: 0;
        }
        
        .right {
            width: 200px;
            height: 600px;
            background: rgb(7, 190, 53);
            position: absolute;
            right: 0;
            top: 0;
        }
        
        .content {
            margin: 0 200px;
            background: beige;
            height: 600px;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="nav">导航</div>
        <div class="main">
            <div class="left">左边</div>
            <div class="content">中间</div>
            <div class="right">右边</div>
        </div>
        <div class="footer">底部信息</div>
    </div>
</body>

</html>

运行实例 »

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


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>Document</title>
    <style>
        .box {
            width: 800px;
            overflow: hidden;
            background: burlywood;
            margin: 0 auto
        }
        
        .nav {
            width: 800px;
            height: 50px;
            background: aquamarine;
            float: left;
        }
        
        .footer {
            width: 800px;
            height: 50px;
            background: rgb(207, 158, 21);
            float: left;
        }
        
        .main {
            width: 800px;
            min-height: 600px;
            float: left;
            background: rgb(31, 10, 223);
        }
        
        .left {
            width: 200px;
            height: 600px;
            background: brown;
            float: left;
        }
        
        .right {
            width: 200px;
            height: 600px;
            background: rgb(7, 190, 53);
            float: left;
        }
        
        .content {
            width: 400px;
            height: 600px;
            float: left;
            background: beige;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="nav">导航</div>
        <div class="main">
            <div class="left">左边</div>
            <div class="content">中间</div>
            <div class="right">右边</div>
        </div>
        <div class="footer">底部信息</div>
    </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+教程免费学