博主信息
博文 5
粉丝 0
评论 0
访问量 4401
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
css布局原理与实现--2019.09.04
Morning Star的博客
原创
767人浏览过

清除子级对父级的影响的方法:

html

<body>
<div class="box1">
        <div class="box2">
            子区块
        </div>
        <!-- <div class="clear"></div> -->
    </div>
</body>

css:

.box1 {
    width: 300px;
    border: 5px dashed red;
}
.box2 {
    width: inherit;
    height: 300px;
    background-color: aqua;
    float: left;
}

方法一:

父级元素高度设置=子元素一样的高度*

css

.box1 {
    height: 300px;
}

方法二:

父元素一起嗨起来

css:

.box1 {
    float: left;
}

方法三:添加一个元素,抵消上一个元素的浮动 

css:

.clear {
    clear: both;
}

方法四:给父级元素添加overfloer,专门来清除浮动

css:

.box1 {
    overflow: hidden;
}

三列布局(绝对定位+浮动定位)

html:

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>

绝对定为css:

.container {
    width: 1000px;
    margin: auto;
}
.header {
    height: 60px;
    background-color: lightgray;
}

.footer {
    height: 60px;
    background-color: lightgray;
}
.main {
    /* min-height: 800px;用内容来撑开高度 */
    background-color: aquamarine;
    margin: 5px auto;
}

.left {
    width: 200px;
    min-height: 800px;
    background-color: green;
}
.content {
    min-height: 800px;
    background-color: red;
}
.right {
    width: 200px;
    min-height: 800px;
    background-color: green;
}
.main {
    /* 给定位父级设置定位属性  可以是相对 也可以是绝对 */
    position: relative;
}
.left {
    position: absolute;
    left: 0;
    top: 0;
}
.right {
    position: absolute;
    top: 0;
    right: 0;
}
/* 内容区通过挤压得到的 margin */
.content {
    margin-left: 200px;
    margin-right: 200px;
}

浮动css:

.container {
    width: 1000px;
    margin: auto;
}
.header {
    height: 60px;
    background-color: lightgray;
}
.footer {
    height: 60px;
    background-color: lightgray;
}
.main {
    /* min-height: 800px;用内容来撑开高度 */
    background-color: aquamarine;
    margin: 5px auto;
    overflow: hidden;
}

.left {
    width: 200px;
    min-height: 800px;
    background-color: green;
}
.content {
    min-height: 800px;
    background-color: red;
}
.right {
    width: 200px;
    min-height: 800px;
    background-color: green;
}
/* 浮动 */
.left {
    float: left;
}
.right {
    float: right;
}

.content {
    float: left;
    width: 600px;
}

样式:

4PKX~0}SP8(ZI7BUAN$IK]G.png

                            

                                                总结

     主要学习了如何清除浮动的影响(best:overflow:hidden)。了解了相对定位,绝对定位,固定定位。在制作登录网页时了解了要设置遮和透明度(opacity),在二维码图片区设置了父子元素,通过移动父级元素调整。在制作招生广告时,使用了js代码,cursor: pointer改变鼠标形状。

     在配置三列布局中:父级元素设置定位属性可以随意设置不用注意,主题的高度由内容来撑开.

     


批改状态:合格

老师批语:看来你是缺了不少作业了, 布局才开始写, 加油呀
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系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+教程免费学