登录  /  注册
博主信息
博文 26
粉丝 1
评论 2
访问量 21013
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
9月4日CSS的定位元素作业
星空的博客
原创
703人浏览过

一作业:消除子元素浮动造成父元素高度折叠的影响

实例

<!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>
</head>
<style>
    .box1 {
        width: 300px;
        border: 5px dashed red;
    }
    
    .box2 {
        width: inherit;
        height: 300px;
        background-color: aqua;
    }
    
    .box2 {
        float: left;
    }
    
    .box1 {
        overflow: hidden;
    }
</style>

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

</html>

运行实例 »

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

QQ截图20190905182450.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>绝对定位3列布局</title>
</head>

<style>
    .zuoye {
        height: 1000px;
        width: 1200px;
        margin: 0 auto;
    }
    
    .top,
    .footer {
        height: 40px;
        background-color: bisque;
    }
    
    .main {
        height: 800px;
        position: relative;
    }
    
    .zuo {
        height: 800px;
        width: 200px;
        background-color: crimson;
        position: absolute;
        left: 0;
        top: 0;
    }
    
    .zhong {
        height: 800px;
        width: 800px;
        background-color: darkorange;
        position: absolute;
        left: 200px;
        top: 0;
    }
    
    .you {
        height: 800px;
        width: 200px;
        background-color: cyan;
        position: absolute;
        left: 1000px;
        top: 0;
    }
    
    .top {
        margin-bottom: 10px;
    }
    
    .footer {
        margin-top: 10px;
    }
</style>

<body>
    <div class="zuoye">
        <div class="top">头部</div>

        <div class="main">
            <div class="zuo">内容左边</div>
            <div class="zhong">内容中间</div>
            <div class="you">内容右边</div>

        </div>

        <div class="footer">底部</div>
    </div>

</body>

</html>

运行实例 »

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

QQ截图20190905182500.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>浮动3列布局</title>
</head>
<style>
    .zuoye {
        margin: 0 auto;
        height: 900px;
        width: 1200px;
    }
    
    .top,
    .footer {
        height: 40px;
        background-color: darkslateblue;
    }
    
    .top {
        margin-bottom: 10px;
    }
    
    .footer {
        margin-top: 10px;
    }
    
    .main {
        margin: 5px auto;
        overflow: hidden
    }
    
    .zuo {
        height: 700px;
        width: 300px;
        background-color: blue;
        float: left;
    }
    
    .zhong {
        height: 700px;
        width: 600px;
        background-color: lightpink;
        float: left;
    }
    
    .you {
        height: 700px;
        width: 300px;
        background-color: green;
        float: left;
    }
</style>

<body>
    <div class="zuoye">
        <div class="top">头部</div>

        <div class="main">
            <div class="zuo">内容左边</div>
            <div class="zhong">内容中间</div>
            <div class="you">内容右边</div>

        </div>

        <div class="footer">底部</div>
    </div>

</body>

</html>

运行实例 »

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

QQ截图20190905182411.png

请老师批改看看,按老师的原理,我自己布局方法不知道行不行?谢谢!


批改状态:合格

老师批语:作业写得很棒, 坚持 下去
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

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

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