我的问题是,我无法将文本水平居中对齐。在垂直方向上,我将它对齐到中心,但在水平方向上,我不能。 (当文本较长时,它水平居中?!如果我没看错的话。)
我尝试添加 <a>
元素 display:block
和 text-align:center
,但这并没有解决我的问题。
我附上了网站的照片。 Photo-Click here
<a>
元素在 <h2>
中元素。
<h2>
CSS:
line-height: 22px;
margin-top: 10px;
margin-bottom: 5px;
font-size: 16px;
height: 55px;
font-weight: 600;
display: flex;
align-items: center;
text-align: center;
<a>
- 元素 css:
color: #333;
-webkit-transition: color .5s;
-moz-transition: color .5s;
-ms-transition: color .5s;
-o-transition: color .5s;
transition: color .5s;
我做错了什么?
最佳答案
如果没有看到您的代码与其余 html 和 css 的上下文,我会将 justify-content: center ;
放在父元素上,即 h2。我假设这设置为宽度的 100% 以匹配图像的宽度。
检查一下关于 flex 的完整信息: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
关于html - 可以将文本对齐到 flex 显示的中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53342325/