css - 将子 Div 与 Display Inline-Block 居中对齐并设置 float 向左

标签 css alignment center

我这里有一个工作代码:http://jsfiddle.net/V3Suq/29/

问题

如何让 child 左对齐,例如像这样的截图:Screenshot

HTML

<div class="parent">
    <div class="child"></div>
    <div class="child"></div>
    <div class="child"></div>
    <div class="child"></div>
</div>

CSS

.parent {
    width: 100%;
    background: #f00;
    height: 210px;
   text-align: center;
}

.child {
    width: 150px;
    height: 100px;
    background: #000;
    margin: 0 auto;
    display: inline-block;
    overflow: hidden;
}

最佳答案

使用 parent 类设置 text-align: left; 并将宽度从 % 更新为 px 像这样width: 500px; 并将 padding-left 设置为一些 px,因此更新后的 parent 类看起来像

.parent {
    width: 500px;
    background: #f00;
    height: 210px;
    text-align: left;
    padding-left:50px;
}

FIDDLE 是 HERE

关于css - 将子 Div 与 Display Inline-Block 居中对齐并设置 float 向左,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27916875/

相关文章:

jquery - 在整个网站上弹出 Div? (在第一个页面加载时)

html - 使用 CSS 垂直居中 3 个段落

html - 如何修复菜单在 wordpress 中不居中

ios - 使用自动布局水平对齐 5 个按钮的最佳方法是什么

swift - 快速对齐 4 个标签与自动布局

css - div(并排)的内联对齐,中间有一点空间

html - 如何在 CSS 中使文本居中并且最大宽度为 800px?

javascript - 复选框内的图像

html - 尝试呈现按钮控件时,Angular innerHTML 属性不起作用

html - 嵌入字体不适用于 Wordpress 样式表