alignment - div内双元素的水平居中
问题描述
能够并排放置图像和文本,使它们垂直对齐,但是我怎样才能将整个拍摄匹配水平居中对齐。已经在“picturetalk”div 中尝试过“text-align: center”。
<?php if( get_field('picturetalk') ): ?>
<div class="picturetalk">
<div>
<img class="style-svg" src="/wp-content/uploads/2020/07/speech-bubble.svg" />
</div>
<div>
"<em><?php the_field('picturetalk_content'); ?></em>"
</div>
</div>
<?php endif; ?>
.picturetalk {
display: flex;
align-items: center;
font-size: larger;
background-color: #fff;
border: 1px solid #000;
}
输出:
https://drive.google.com/file/d/1-ojCcfeUQpJQFDQVIR_w4UfNahHVRoX2/view?usp=sharing
谢谢,
解决方案
justify-content:center;
将此样式添加到picturetalk
请试试这个
.picturetalk {
display: flex;
align-items: center;
background-color: #fff;
border: 1px solid #000;
justify-content:center;
color:#515256;
}
<div class="picturetalk">
<div>
<img class="style-svg" src="https://i.stack.imgur.com/XU28O.png" />
</div>
<div>
<em>"Strange object array imaged parallel to star field Clius 3"</em>
</div>
</div>
对于水平和垂直对齐,使用d-flex
这三个是必要的。
display: flex;
align-items: center;
justify-content:center;
推荐阅读
- angular - 在 Stackblitz Angular 项目中使用 Object.values()
- scala - hbase-spark 加载数据引发 NullPointerException 错误(scala)
- openid - OneLogin - OpenID Connect - 无法使用自定义 URL 方案?离子/科尔多瓦
- c# - WPF xaml 动画代码的版本背后的代码
- javascript - 在移动浏览器上为博主修改 Javascript url 的 Base64 编码 (?m=1)?
- sql - Sequelize 不使用模型中的字段别名
- javascript - JavaScript 库 - 如何公开回调函数
- jekyll - Jekyll 自定义主题(本地运行)
- xaml - Xamarin XAML: Setting Attached Property in Code
- angular - 如何在 Angular 6 中处理 401 未经身份验证的错误