【发布时间】:2018-01-27 10:10:08
【问题描述】:
如何将“scoreBox”内的元素水平居中?
它们目前只是左对齐。
.voteButtons {
display: inline-block;
text-align: center;
}
.HP {
display: inline-block;
text-align: center;
width: auto !important;
margin-left: 5px !important;
}
.scoreBox {
display: flex;
margin-top: 10px;
padding-top: 10px;
text-align: center;
width: auto !important;
}
<div class="scoreBox">
<span class="voteButtons"><img class="UpvoteButton" id="voteUp" src="..."><img class="DownvoteButton" id="voteDown" src="..."></span>
<div class="HP">
<%= post.upvotes - post.downvotes%> score </div>
</div>
【问题讨论】:
-
@axlj 我已经看到了。我也认为这很可能以前已经回答过了,但我似乎无法找到一种方法来做这么简单的事情......我需要 3 个元素保持靠近并居中。
-
第 6 个答案有 Flexbox 版本,
justfy-content: center...只需从您发布的代码中删除display: flex即可:jsfiddle.net/036euku1