如何修复div中文本而不是图像的对齐方式?

时间:2020-09-25 15:37:10

标签: html alignment

是否可以将我的文本与垂直中间对齐。我使用过valigntext-alignpadding,但无法使用。另外,我不希望任何图像与文本对齐。

解决方案只需要HTML。enter image description here

body {
    background-color: #6B6B6B;
    margin: 50px;
<div style="background:#2f2f2f;height:42px;width:250px;"><i><b style="padding-top:10px;text-align:middle">Text</a></div>

3 个答案:

答案 0 :(得分:1)

只需添加到div。

display: flex;
align-items: center;

body {
    background-color: #6B6B6B;
    margin: 50px;
<div style="background:#2f2f2f;height:42px;width:250px;display: flex;
align-items: center;"><i><b style="padding-top:10px;text-align:middle">Text</a></div>

此外,html格式无效,更好的代码如下:

body {
    background-color: #6B6B6B;
    margin: 50px;
}

   .container {
    background: #2f2f2f;
    height: 42px;
    width: 250px;
    display: flex;
    align-items: center;
}
<div class="container">
    <span>Text</span>
</div>

答案 1 :(得分:0)

我想就是这个。如果要使文本居中,只需编写以下代码:

text-align: center;

答案 2 :(得分:0)

您的HTML有一些语法错误,在这种情况下,您需要使用负边距来对齐底部中心。

body {
  background-color: #6B6B6B;
}

.bottomcenter {
    position:absolute;
    width:300px;
    height:300px;
    bottom:0px;
    right:25%;
    left:50%;
    margin-left:-150px;
    color:white;
}
<div style="background:#2f2f2f;height:42px; text-align:center;" class="bottomcenter"><i><a style="padding-top:10px;">Text</a></i></div>