【发布时间】:2016-10-28 19:50:04
【问题描述】:
我正在尝试在 <a> 标记中的 div 中将图像垂直居中,但我无法让 CSS 将图像垂直居中。
div {
height: 7rem;
width: 90%;
text-align: center;
margin: 1.25rem auto;
padding: 0 5.5rem 0 5.5rem;
font-size: .8rem;
border-style: solid;
border-width: .08rem;
}
div * {
position: relative;
top: 50%;
transform: translateY(-50%);
}
div img {
width: 4rem;
}
div div {
margin: 0 auto;
width: 4rem;
height: 100%;
}
<div class="footer">
<div id="footerhome">
<a href="https://www.google.com">
<img src="http://images.clipartpanda.com/smiley-face-transparent-background-tumblr_mdv6nltwdB1qdic05o1_500.gif" />
</a>
</div>
</div>
这是我目前正在使用的: http://codepen.io/SamanthaBae/pen/LRomdr
我已经尝试过将图像设置为包含它的 div 的背景图像并在其间插入<a> 标记的解决方案,但它似乎不能作为链接工作,即使我可以得到它垂直对齐:
【问题讨论】:
-
问题与
div *规则有关。这样做的目的是什么?如果没有目的,将其删除,这将解决大部分问题,但不是全部。如果需要,那就另当别论了。