html - 如何在 CSS 中正确对齐图片

标签 html css

我有 3 个图标,我想将它们居中对齐 我尝试了不同的代码,但到目前为止没有任何效果,我尝试为其添加边距,但问题是它在它们之间添加了不必要的空间,所以我希望它们彼此靠近,有没有办法将 margin-right 放在它上面并从那里删除空间? 我只想将它们对齐到我的段落下方,但在它的中心。
到目前为止,这是我的代码。

    #body a img {
      width: 50px;
      height: 50px;
      margin-top: 50px;
      margin-right: 200px;
    }
<div id="body">
  <p class="text">We are a group of friends that enjoy playing League Of Legends togather, feel free to follow us on our different website medias</p>
  <div class="icons">
    <a href="https://www.youtube.com/themunkiuke">
      <img class="icon1" src="images/youtube.png">
    </a>
    <a href="http://www.twitch.tv/siminios">
      <img class="icon2" src="images/twitch.png">
    </a>
    <a href="http://yinochi.deviantart.com/gallery/">
      <img class="icon3" src="images/art.png">
    </a>
  </div>

最佳答案

会不会是一个简单的text-align缺失?

#body a img {
      width: 50px;
      height: 50px;
    }
.icons {
  text-align:center;
  }
<div id="body">
  <p class="text">We are a group of friends that enjoy playing League Of Legends togather, feel free to follow us on our different website medias</p>
  <div class="icons">
    <a href="https://www.youtube.com/themunkiuke">
      <img class="icon1" src="images/youtube.png">
    </a>
    <a href="http://www.twitch.tv/siminios">
      <img class="icon2" src="images/twitch.png">
    </a>
    <a href="http://yinochi.deviantart.com/gallery/">
      <img class="icon3" src="images/art.png">
    </a>
  </div>

关于html - 如何在 CSS 中正确对齐图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35612162/

相关文章:

html - 似乎 IE 动画/处理我的 loading.gif 即使我设置了显示 :none?

带有粘性标题的 HTML 表格 - 单元格宽度问题

javascript - Div 中的垂直/水平对齐

html - overflow hidden 但没有滚动条的可滚动区域

php - JQuery 没有执行 - 但它正在加载?

javascript - 我应该如何改进我的 jQuery 点击功能?

html - 我的 Github 页面不会将自定义 css 文件应用到网站

html - 我很难为我的 body 命名

css - 根据 <li> 大小在 <ul> 中居中 <li> 元素

css - 垂直居中 div 成一个 div