Blogger Information
Blog 9
fans 0
comment 1
visits 6028
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
9月4日作业:实例演示子元素浮动造成父元素高度折叠的影响,三列布局
张大千的博客
Original
566 people have browsed it
  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: 500px;
            background-color: blue;
            border: 1px dashed #ff0000;
        }
        
        .box1 {
            width: 200px;
            height: 200px;
            background-color: aquamarine;
            float: left;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="box1">子元素浮动</div>
    </div>
</body>

</html>

运行实例 »

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

解决办法高度折叠的办法就是给父元素加上overflow: hidden;

实例

<!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: 500px;
            background-color: blue;
            border: 1px dashed #ff0000;
            /*解决办法高度折叠的办法就是给父元素加上overflow: hidden;*/
            overflow: hidden;
        }
        
        .box1 {
            width: 200px;
            height: 200px;
            background-color: aquamarine;
            float: left;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="box1">子元素浮动</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>
        .pre {
            width: 1000px;
            height: auto;
            margin: 0 auto;
        }
        
        .header {
            width: 1000px;
            height: 50px;
            background-color: blueviolet;
        }
        
        .main {
            width: 1000px;
            min-height: 800px;
            background-color: bisque;
            position: relative;
        }
        
        .footer {
            width: 1000px;
            height: 60px;
            background-color: aquamarine;
        }
        
        .left {
            width: 150px;
            height: 800px;
            background-color: #369852;
        }
        
        .middle {
            background-color: antiquewhite;
            width: 700px;
            height: 800px;
        }
        
        .right {
            width: 150px;
            height: 800px;
            background-color: brown;
        }
        /*绝对定位实现三列布局*/
        
        .left {
            position: absolute;
            left: 0;
            top: 0;
        }
        
        .right {
            position: absolute;
            top: 0;
            right: 0;
        }
        
        .middle {
            margin: 0 150px;
        }
    </style>
</head>

<body>
    <div class="pre">
        <div class="header">头部</div>
        <div class="main">
            <div class="left">左侧</div>
            <div class="middle">中间</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>
        .pre {
            width: 1000px;
            height: auto;
            margin: 0 auto;
        }
        
        .header {
            width: 1000px;
            height: 50px;
            background-color: blueviolet;
        }
        
        .main {
            width: 1000px;
            min-height: 800px;
            background-color: bisque;
            overflow: hidden;
        }
        
        .footer {
            width: 1000px;
            height: 60px;
            background-color: aquamarine;
        }
        
        .left {
            width: 150px;
            height: 800px;
            background-color: #369852;
        }
        
        .middle {
            background-color: antiquewhite;
            width: 700px;
            height: 800px;
        }
        
        .right {
            width: 150px;
            height: 800px;
            background-color: brown;
        }
        /*浮动定位实现*/
        
        .left {
            float: left;
        }
        
        .right {
            float: right;
        }
        
        .middle {
            width: 700px;
            float: left;
            margin: 0 auto;
        }
    </style>
</head>

<body>
    <div class="pre">
        <div class="header">头部</div>
        <div class="main">
            <div class="left">左侧浮动定位实现</div>
            <div class="middle">中间浮动定位实现</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
Author's latest blog post