css - 如何水平对齐两个
问题描述
我正在使用 <figure> 显示两个图像,并且我希望两个 <figure> 水平内联,而服务 div 位于页面中心。我的 div 居中,但我无法让 <figure> 对齐。我试过“显示:内联块;” 但它似乎不起作用。我究竟做错了什么?
.services {
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
flex-direction: column;
-webkit-flex-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
flex-direction: column;
align-items: center;
align-self: center;
justify-content: center;
flex-wrap: wrap;
font-size: 20px;
text-align: center;
}
.figurecenter figure {
display: inline-block;
}
.figurecenter figcaption {
margin: 0 auto;
}
<div class="services">
<figure class="figurecenter">
<h1>PHSR</h1><br>
<img width="268" height="133" alt="Pre-Start Health and Safety Review image" src="http://www.cafenocturne.com/RackInspections/images/MainImage-1-GUY.png"><br><br>
<figcaption>PHSR (Pre-Start Health & Safety Review)?<br>We can help.</figcaption><br>
<a href="about/phsr.html" class="button" title="Click here to read more about PHSR">READ MORE</a><br><br>
</figure>
<figure class="figurecenter">
<h1>Inspections</h1><br>
<img width="268" height="133" alt="Inspections image" src="http://www.cafenocturne.com/RackInspections/images/MainImage-2-Wrench.png"><br><br>
<figcaption>Rack inspections identify safety concerns and deficiencies with rack storage systems.</figcaption><br>
<a href="about/inspections.html" class="button" title="Read more about our inspection process">READ MORE</a>
</figure>
<div style="clear: both;" > </div>
</div>
请忽略损坏的按钮和其他东西,因为当我的问题只是让两个 <figure> 并排排列时,我不想为我的工作包含整个样式表。
解决方案
你也可以做到这一点margin-bottom: auto
。
查看片段时请点击“整页”
.services {
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
-webkit-flex-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
flex-direction: row;
align-items: center;
align-self: center;
justify-content: center;
flex-wrap: wrap;
font-size: 20px;
text-align: center;
}
.figurecenter {
flex: 1;
margin-bottom: auto;
}
.figurecenter figure {
display: inline-block;
}
.figurecenter figcaption {
margin: 0 auto;
}
<div class="services">
<figure class="figurecenter">
<h1>PHSR</h1><br>
<img width="268" height="133" alt="Pre-Start Health and Safety Review image" src="http://www.cafenocturne.com/RackInspections/images/MainImage-1-GUY.png"><br><br>
<figcaption>PHSR (Pre-Start Health & Safety Review)?<br>We can help.</figcaption><br>
<a href="about/phsr.html" class="button" title="Click here to read more about PHSR">READ MORE</a><br><br>
</figure>
<figure class="figurecenter">
<h1>Inspections</h1><br>
<img width="268" height="133" alt="Inspections image" src="http://www.cafenocturne.com/RackInspections/images/MainImage-2-Wrench.png"><br><br>
<figcaption>Rack inspections identify safety concerns and deficiencies with rack storage systems.</figcaption><br>
<a href="about/inspections.html" class="button" title="Read more about our inspection process">READ MORE</a>
</figure>
<div style="clear: both;" > </div>
</div>
推荐阅读
- javascript - bExpress bodyparser 配置不正确
- android - android保持Cast Volume通知处于暂停状态
- c# - 如何在面板中绘制从另一个类调用方法
- reactjs - UseState initialState 基于异步值
- ios - 如何重置或清除 UI 视图
- javascript - Javascript:优雅的正则表达式
- c# - 绑定不知从何而来
- flutter - heightFactor 和 widthFactor 是如何工作的?
- php - 如何覆盖 woocommerce 自定义面板文件(包含在文件夹中)
- java - 如何在应用程序上下文之前评估 spring ApplicationArguments?