【发布时间】:2019-05-16 05:50:34
【问题描述】:
我有一排四个 li 容器,每个容器里面都有 H3 文本。我希望文本垂直和水平居中,但只能垂直居中。多次尝试使用垂直对齐:中间;但没有运气。这是我正在使用的。
HTML:
<ul class="products oceanwp-row clr grid shop-variety">
<li style="background-image: url( http://flowerlinkla.com/staging/wp-content/uploads/2018/12/bkg-garden-rose.jpg ) !important;" class="shop-variety product col span_1_of_4"><div class="shop-content"><h3>Garden Rose</h3></div></li>
</ul>
CSS:
.shop-variety.product.col.span_1_of_4 {
height: 285px;
width: 24%;
margin: 24px .5%;
text-align: center;
display: table-cell;
vertical-align: middle;
}
应该提到我也尝试过 display: flex。没有运气。
【问题讨论】:
-
你把它水平居中了。
标签: html css flexbox vertical-alignment