绝对定位里面相对定位?

绝对定位里面相对定位?,第1张

绝对定位里面相对定位?

一个很好的例子是当您想将某些内容放置到页面上或相对于容器/ div放置时。

这向您显示,如果绝对div不在“相对” div内,则内容将与文档主体对齐

请注意,绿色div(

#box1
position: relative
的div内部(
#inner1
)的对齐方式为的上/右对齐
#box1

蓝色框(

#box2
)具有与绿色框(
#box1
)完全相同的HTML布局,但不包含
position:relative
且注意其中的div(
#inner2
)对齐到顶部的右/右
body

#box1, #box2 {    width: 100px;    height: 100px;    color: white;    text-align: center;    line-height: 100px;}#box1 {    background: green;    position: relative;}#box2 {    background: blue;}#inner1, #inner2 {    width: 50px;    height: 50px;    top: 0;    right: 0;    position: absolute;    background: black;    opacity: 0.5;    color: white;    text-align: center;    line-height: 50px;}

这是克里斯·科耶尔(Chris Coyier)撰写的一篇不错的文章。

具有相对位置的页面元素使您可以控制在其中绝对放置子元素的位置。



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5112430.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-17
下一篇2022-11-17

发表评论

登录后才能评论

评论列表(0条)

    保存