html - 在父级内水平居中

标签 html css jquery-isotope

关于 this page我展示了出现在音乐节上的艺术家名单。艺术家的安置<div> s 由 isotope 控制(当有大量艺术家并且艺术家 div 的高度不同时,单独使用 CSS 很难让所有内容正确排列)。

无论如何,我想将艺术家 div 在其父容器中居中,以便艺术家的左右两侧有相等数量的空白,如下图所示。

enter image description here

我已经尝试了所有显而易见的事情,例如:

margin: 0 auto
text-align: center

但到目前为止还没有运气....

最佳答案

parent 必须有

text-align:center; width:abc;

和一定的宽度。那么 child 应该有

margin:auto; text-align:left; width:xyz;

例子:

<div style="width:100%; text-align:center;">
    <div style="width:50%; text-align:left; background:red; margin:auto;">
        This will do it just right
    </div>
</div>

如果这不起作用,您真的应该检查是否有其他因素影响了该行为!

关于html - 在父级内水平居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16638982/

相关文章:

html - Bootstrap 列的中心内容

html - min-width 的动态变化

javascript - 仅限 Safari 浏览器中的右边距

html - CSS-Centering-多行

jQuery Isotope 插件不会将所选元素排序到左上角

javascript - 带有 HTML 表格的 jQuery 同位素库

html - 按属性条件删除某些div

iphone - iphone上的网站问题

css - 在嵌套的 flexbox 内滚动

javascript - 同位素和图像加载布局不填充空间全宽