html - 在页面调整大小时动态居中 block ?

标签 html css centering

无论屏幕尺寸如何,我都希望这些 block 始终位于页面的中央。

http://seriouslyineedthis.com/

问题是它总是向左浮动。

*我使用的是 Masonry 插件,但存在重叠问题(所以我不希望这是一个答案)。

在代码中我只是这样做:

<div id="content_holder_outside">
<div id="content_holder">
     <!-- Blocks and content go here -->
</div>
</div>

#content_holder_outside {
    width:100%;
    text-align:center;
    float:left;
    }

#content_holder {
    min-height:600px;
    }

它非常简单,但行不通。一切都仍然向左浮动。有什么想法吗?

最佳答案

如果您将 display: inline-block; 添加到您的 #each_box_holder 并从中删除 float:left,它将保持居中。

注意:将其从 id 更改为 classid 应仅在其唯一 时使用。在你的情况下它不是,所以使用 class 更好,并且会为你在功能方面省去很多麻烦。

关于html - 在页面调整大小时动态居中 block ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23639510/

相关文章:

html - 向上而不是向下缩放 div?

javascript - 如果元素是唯一的,使用 javascript 更改 ID 是一种好的做法吗?

html - 使用 CSS 制作静态/粘性菜单栏

css - 为什么这在 Firefox、Chrome 和 IE 中的工作方式不同?

html - 使用 CSS 背景阴影/图像打印 HTML 页面

html - 在 html/xhtml 中解析 RDFa?

html - 使用CSS在div中定位图像和文本

css - 响应式背景图片 : How to handle height?

java - Netbeans IDE 6.91 "center horizontally"不可点击

java - 像 Microsoft 一样居中文本