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
Html 使用css的具有动态宽度的水平中心div_Html_Css - Fatal编程技术网

Html 使用css的具有动态宽度的水平中心div

Html 使用css的具有动态宽度的水平中心div,html,css,Html,Css,我已经看过一百万篇关于这个主题的博客文章,但我找不到解决我具体问题的方法。我的设置如下所示: <div id="wrapper" style="position:absolute; max-width:500px; min-width:300px; width:100%"> </div> 如何使用CSS使包装器居中。页边距:自动将不起作用。它的样式是位置:绝对,因此您要么必须这样更改: style="position:absolute; max-width:50

我已经看过一百万篇关于这个主题的博客文章,但我找不到解决我具体问题的方法。我的设置如下所示:

<div id="wrapper" style="position:absolute; max-width:500px; min-width:300px; width:100%"> </div>


如何使用CSS使包装器居中。页边距:自动将不起作用。

它的样式是
位置:绝对
,因此您要么必须这样更改:

style="position:absolute; max-width:500px; min-width:300px; width:100%"
/* changes to: */
style="margin: 0px auto; max-width:500px; min-width:300px; width:50%"
/* width changes so that there's actually room to center */
或者,如果您想保持
位置:绝对
,则必须使用Javascript手动设置x和y位置


如果你的意思是想把里面的东西居中,只需添加
text align:center

您是否尝试过给包装设定宽度而不是100%,然后设置边距:自动?

您需要使用
边距:0自动
页边距:自动。最初我也犯了同样的错误。

宽度:100%,那么您希望它做什么呢-