Css 更新边距:调整div大小时自动
是否可以将一个div居中放置在div中,这样当父div调整大小时,它仍然保持在中心位置?到目前为止,我试过了 保证金:0自动;和 左边距:自动;右边距:自动 这两种方法都有效,但是一旦div大小更改,它就不会重新定位。谢谢 标记:Css 更新边距:调整div大小时自动,css,Css,是否可以将一个div居中放置在div中,这样当父div调整大小时,它仍然保持在中心位置?到目前为止,我试过了 保证金:0自动;和 左边距:自动;右边距:自动 这两种方法都有效,但是一旦div大小更改,它就不会重新定位。谢谢 标记: <div id='bottomcontent' style="float: left; position: absolute; left: 0; bottom: 0; background-color:#0b0b0b; height:100px; width:7
<div id='bottomcontent' style="float: left; position: absolute; left: 0; bottom: 0; background-color:#0b0b0b; height:100px; width:796px;">
<div id="bottomleftbutton" style="margin-left: 25px;">stuff here </div>
<div id="bottomcentertext" style="margin-left: auto; margin-right: auto;">so far
<h4>17</h4>
places match your criteria</div>
<div id="bottomrightbutton" style="float: right; margin-right: 25px;">stuff here </div>
</div>
这里的东西
目前为止
17
地点符合你的标准
这里的东西
使用以下内容设置内部div的样式:
position:absolute;
top:0;
bottom:0;
left:0;
right:0;
margin:auto;
请参见此处的一个示例:以便获得
页边距:自动
要工作,您需要在div
上设置一个宽度
如果你做了这样的事
<div id="bottomcentertext" style="
margin-left: auto;
margin-right: auto;
width:300px; //NEW
color:white;">
它起作用了
示例:将需要一些相关的标记。hmmmm。。。它确实有效:我编辑了我的第一篇帖子:“bottomcentertext”是我无法重新定位的内容。你能把问题中的标记放到相关上下文中吗?因为上面的提琴确实有效,错误就在别处,也许在现有的css中?谢谢Marcel和Jonas!我(实际上whg)已经解决了这个问题。谢谢你的帮助!:)