HTML 的
<div style="width:50%;overflow:hidden">
<div id="inboxHeader">
<div id="inboxCount"><p>Earth</p></div>
</div>
</div>
CSS
#inboxHeader{
background-color:yellow;
height :300px;
position: relative;
}
#inboxCount{
position: absolute;
bottom: 0;
float:right;
}
Earth
位于bottom left
角落。那么如何将其转移到bottom right
角落?
答案 0 :(得分:5)
设置right:0
而不是float:right
答案 1 :(得分:1)
因为它是float:right;
right: 0px;
如果它位于相对位置,那么你需要float
它到right
但是绝对定位会从DOM的流中移除元素。
但有一点需要注意,请确保父元素根据需要将其位置设置为relative
或absolute
,或者子元素可以将自己定位在DOM树中的最高位置有位置设置。
答案 2 :(得分:0)
float
- ing对absolute
- 定位元素没有影响。改为设置right
属性。
所以,改变一下:
#inboxCount{
position: absolute;
bottom: 0;
float:right;
}
对此:
#inboxCount{
position: absolute;
bottom: 0px;
right: 0px;
}
答案 3 :(得分:0)
HTML
<div style="width:50%;overflow:hidden">
<div id="inboxHeader">
<div id="inboxCount">
<p>Earth</p>
</div>
</div>
</div>
CSS
#inboxHeader { background-color:yellow; height :300px; position: relative; } #inboxCount { position: absolute; bottom: 0; right: 0; /* No need for float:right with absolute positioning */ }
我已更新您的Demo
答案 4 :(得分:0)
答案 5 :(得分:0)
只需发布一个描述性答案,这样可能有助于某人。
位置属性可用于解决此问题
<div id="outer" style="width: 400px; height: 400px; border: 1px solid red; position: relative">
<div id="inner" style="width: 200px; height: 200px; border: 2px solid yellow; right:0;bottom:0;position:absolute;">
</div>
如果我们在外部设置相对定位&#39; div,外部的任何元素&#39; div将相对于&#39;外部&#39; DIV。然后,如果我们在内部设置绝对定位&#39; div,我们可以将它移到&#39;外部&#39;的右下角。 div使用&#39; right&#39;和&#39;底部&#39;属性。
相对: 如果指定position:relative,则可以使用top或bottom,left或right来相对于文档中通常出现的位置移动元素。
它的真正含义是&#34;相对于自身&#34;。如果设置position:relative;在一个元素上但没有其他定位属性(顶部,左侧,底部或右侧),它根本不会影响它的位置,它将完全像您将它保留为position:static;但是如果你给它一些其他的定位属性,比如top:10px;,它会将它的位置从它正常的位置向下移10个像素。
绝对:当您指定position:absolute时,该元素将从文档中删除,并准确放置在您告诉它的位置。还有一种定位类型,允许您将任何页面元素准确地放置在您想要的位置。
任何相对定位元素的子元素都可以绝对定位在该块中。
参考文献: