Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.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 无法居中div尝试浮动到左文本对齐页边距:自动无法工作_Html_Css - Fatal编程技术网

Html 无法居中div尝试浮动到左文本对齐页边距:自动无法工作

Html 无法居中div尝试浮动到左文本对齐页边距:自动无法工作,html,css,Html,Css,无法居中div尝试将其浮动并使用文本对齐:居中margin:auto不起作用,请帮助我,我想不出来。我将粘贴代码和jfiddle的链接 它在JFIDLE中看起来不错,但实际上不是,我不知道为什么。我用的是铬 我想我给出了相同的解决方案,在这个问题上,考虑到您的标记显示:table是一个更好的选择(如果您可以忽略IE8-) display:table整体兼容(IE8+),css最少 看 HTML <div class="center" style="display:table">

无法居中div尝试将其浮动并使用
文本对齐:居中
margin:auto
不起作用,请帮助我,我想不出来。我将粘贴代码和jfiddle的链接

它在JFIDLE中看起来不错,但实际上不是,我不知道为什么。我用的是铬


我想我给出了相同的解决方案,在这个问题上,考虑到您的标记
显示:table
是一个更好的选择(如果您可以忽略IE8-)

display:table
整体兼容(IE8+),css最少

HTML

 <div class="center" style="display:table">
        <div class="cleft_portion" style="display:table-cell">

        </div>

        <div class="mid_portion" style="display:table-cell">

        </div>

        <div class="cright_portion" style="display:table-cell">

        </div>
    </div>
并将此添加到css的顶部:

html, body {
    width:100%;
    height:100%;
}
将宽度设为100%

转到要居中的div并写入:

width:100%
或者稍微调整一下宽度,使其自身居中

保持文本对齐:居中和边距:自动

如果它仍然不居中,您可以始终使用边距右/左,只要它在边距下:0自动

此外,如果你打算做一个最好的浮动,那么:

overflow:hidden;

并使用高度以避免重叠

文本对齐:居中
将不起作用,因为您在代码中使用图像


如果要使用
margin:0 auto
,则必须为要位于中心的容器指定一个宽度,因为默认情况下,容器采用容器的宽度,并且看不到应用的
margin:0 auto

在我的解决方案中添加了一个编辑,请检查这是否有帮助!
width:100%
overflow:hidden;