【问题标题】:HTML/CSS Align objects in center with floatHTML/CSS 使对象居中与浮动对齐
【发布时间】:2015-11-30 16:10:58
【问题描述】:

所以我遇到了这个问题,我想将对象居中对齐,但这些对象有 float: left;

这是 100% 的样子

这是 150% 的样子

代码:

.holder {
text-align: center;
display: table;
margin: auto;
}

.box {
width: 360px;
height: 130px;
border-radius: 2px;
position: relative;
float: left;
margin-left: 10px;
margin-top: 10px;
}

HTML 代码:

<div class="holder">
<div class="box">
</div>
<div class="box">
</div>
<div class="box">
</div>
</div>

【问题讨论】:

  • 你为什么不直接使用display:inline-block;
  • 请发布您完成的代码或提供演示。
  • @alirezasafian 我添加了 HTML 代码

标签: html css web alignment


【解决方案1】:

如果您使用float:left,它将忽略属性text-align:center,因此您可以使用display:inline-block 而不是float:left,它将完美运行。

尝试一次!

【讨论】:

    猜你喜欢
    • 2011-01-18
    • 2023-03-10
    • 2017-05-15
    • 1970-01-01
    • 1970-01-01
    • 2017-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多