html - 无法将图像与 div 中的文本居中对齐

标签 html css web

我正在尝试为带有社交媒体帐户链接的网站创建页脚,但我无法将图像居中。

文本正确居中,但显然图像不是,它们更靠近右边。

这是它的样子: enter image description here

.footer {
  width: 100%;
  margin: 0 auto;
  text-align: center;
  background-color: green;
}

.footer ul{
  list-style: none;
}

.footer ul li {
  font-size: 26px;
  display: inline-block;	
  background-color: red;
  padding-bottom: 3px;
}

.footer a {
  text-decoration: none;
  color: white;
  padding-left:10px;
  padding-right: 10px;
  text-align: center;
}

.footer a:hover {
  color: orangered;
}
.footer p{
  width: 100%;
  text-align: center;
  font-size: 14px;
  font-family: 'Roboto', sans-serif;
}

.footer img{
  text-align: center;
  opacity: 0.7;
  height: 50px;
  width: 50px;
  margin: auto;
  display: inline-block;
}
.footer img:hover{
  opacity: 1.0;
}
<div class="footer">
  <ul>   
    <li><a href="mailto:bannermangavin@gmail.com"><img src="/resources/email.png" alt="mail"></a></li>
    <li><a href="https://uk.linkedin.com/in/gavin-bannerman" target="_blank"><img src="/resources/linkedin.png" alt="linkedin page"></a></li>
    <li><a href="https://github.com/gavinbannerman" target="_blank"><img src="/resources/github.png" alt="github page"></a></li>
  </ul>
  <p>Copyright Company Name &copy; 2016 | All Rights Reserved</p>
</div>

我已经搜索了多个线程,甚至复制了代码,但我似乎无法让它工作。

这是我工作的 fiddle :https://jsfiddle.net/p64q1aru/

最佳答案

您的 ul(列表)有 padding-left 需要重置:

.footer ul {
   list-style:none;
   padding:0;
}

删除填充可以解决问题并集中您的列表元素。

关于html - 无法将图像与 div 中的文本居中对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41262971/

相关文章:

javascript - 如果打开导航栏,则添加过渡到背景颜色更改

html - 在 Jekyll/Ruby 中缩进生成的标记

javascript - 悬停时更改 webkit-scrollbar 宽度时重绘问题

linux - 我正在寻找一个在 FreeBSD 上托管 Web 服务的应用程序

html - 网站上的随机点?

javascript - ng-src 中的函数执行多次

html - CSS、HTML 布局 : relative div inside absolute div flows outside its container

jquery - 为什么这个下拉列表超出窗口

html - 向 HTML 表格添加水平滚动条

windows-phone-7 - 如何在 Windows Phone 7.5 上从网站调用 SMS 撰写?