故如虹,知恩;故如月,知明
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
欢迎加群交流技术

css定位的简单运用

3871人阅读 2019/3/13 11:31 总访问:3941356 评论:0 收藏:0 手机
分类: CSS


父容器使用相对定位position: relative

子容器使用绝对定位position: relative

这样就可以子容器相对父容器定位了,可以写一个自适应样式


例如:要实现一个很简单的列表展示

价格和购买是相对父容器底部10px,买够是自适应整个页面具体右边10px


<div style="position: relative">
    <div>
        <img src="img/b.png" style="max-width: 150px; float: left" />
    </div>
    <div style="height: 100px; float: left;">
        <div>
            <a href="#">苹果笔记本</a>
        </div>
        <div style="margin-top: 10px">
            很厉害笔记本 I5,16G,512SSD
        </div>
        <div style="position: absolute; bottom: 10px;">
            价格:<label style="color: red">$10000</label>
        </div>
        <div style="position: absolute; right: 10px; bottom: 10px">
            <a href="#">购买</a>
        </div>
    </div>

    <hr style="clear: both" />
</div>

这里思路就是最外层div使用相对定位,

里边有需要的就使用绝对定位就可以通过left,top,bottom,rigth等来自适应父容器的位置了



欢迎加群讨论技术,群:677373950(满了,可以加,但通过不了),2群:656732739

评价