如何垂直对齐图像和文本?

约翰·马卡蒂

所以我需要垂直居中图像和文本。但是,我的代码出了点问题,我不知道为什么。我可以让文本居中,但是,图像不是我不知道为什么。有任何想法吗?到目前为止,这是我的代码。

<html>
    <head>
        <style>
 
.container { 
  height: 300px;
  width:300px;
  position: relative;
  border:3px solid black;
  background-color: transparent;
 
}

.center {

  position: absolute;
  top: 50%;
  left: 50%;
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}

.settings {

    width:100px;
    height:100px;
}

.connecttext{
    color: #000;
    text-align: center;
    
}


        </style>
    </head>
    <body>
<div class="container">
  <div class="center">
      <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/69/How_to_use_icon.svg/1200px-How_to_use_icon.svg.png" class ="settings">
         <p class= "connecttext"><strong>Connect</strong><br>Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text 
</p>
      
      
</div>
</div>



    </body>
</html>
             -
弗雷德里希

你应该这样做:

display: flex;
place-items: center;

将这两个添加到您的中心课程中。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章