Blogger Information
Blog 8
fans 0
comment 0
visits 4719
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
消除子元素浮动造成父元素高度折叠的影响,演示三列布局的实现原理( 绝对定位实现, 浮动定位实现)实列演示-2019年9月4号
zzc111的博客
Original
487 people have browsed it

1. 实例演示如何消除子元素浮动造成父元素高度折叠的影响

实例

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

<head>
    <meta charset="UTF-8">
    <title>消除子元素浮动</title>
    <style>
        .box1 {
            width: 300px;
            border: 5px dashed red;
            overflow: hidden;
        }
        
        .box2 {
            width: inherit;
            height: 300px;
            background-color: aquamarine;
            float: left;
        }
    </style>
</head>

<body>
    <div class="box1">
        <div class="box2">
            子元素
        </div>
    </div>
</body>

</html>

运行实例 »

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

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>
        .container {
            width: 1000px;
            margin: 0 auto;
        }
        
        .header,
        .footer {
            height: 60px;
            background-color: lightgray;
        }
        
        .main {
            background-color: lightblue;
            margin: 5px auto;
            position: relative;
        }
        
        .left {
            width: 200px;
            min-height: 800px;
            background-color: lightgrey;
            position: absolute;
            left: 0;
            top: 0;
        }
        
        .content {
            min-height: 800px;
            background-color: lightgreen;
            margin-left: 200px;
            margin-right: 200px;
        }
        
        .right {
            width: 200px;
            min-height: 800px;
            background-color: lightgrey;
            position: absolute;
            top: 0;
            right: 0;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="header">头部</div>
        <div class="main">
            <div class="left">左侧</div>
            <div class="content">内容</div>
            <div class="right">右侧</div>
        </div>
        <div class="footer">底部</div>

    </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>
        .container {
            width: 1000px;
            margin: 0 auto;
        }
        
        .header,
        .footer {
            height: 60px;
            background-color: lightgray;
        }
        
        .main {
            background-color: lightblue;
            margin: 5px auto;
            overflow: hidden;
        }
        
        .left {
            width: 200px;
            min-height: 800px;
            background-color: lightgrey;
            float: left;
        }
        
        .content {
            min-height: 800px;
            background-color: lightgreen;
            float: left;
            width: 580px;
            margin-left: 10px;
        }
        
        .right {
            width: 200px;
            min-height: 800px;
            background-color: lightgrey;
            float: right;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="header">头部</div>
        <div class="main">
            <div class="left">左侧</div>
            <div class="content">内容</div>
            <div class="right">右侧</div>
        </div>
        <div class="footer">底部</div>

    </div>
</body>

</html>

运行实例 »

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


Correction status:qualified

Teacher's comments:写得不错, 没写总结, 下次注意
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