Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 更新边距:调整div大小时自动_Css - Fatal编程技术网

Css 更新边距:调整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居中放置在div中,这样当父div调整大小时,它仍然保持在中心位置?到目前为止,我试过了

保证金:0自动;和 左边距:自动;右边距:自动

这两种方法都有效,但是一旦div大小更改,它就不会重新定位。谢谢

标记:

<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)已经解决了这个问题。谢谢你的帮助!:)