[英]vertical align image and text in div
我有一个包含图像和文本的父div,它们应垂直对齐:中间,尽管我无法正常工作。 不知道我做错了什么。
在我的小提琴下面找到
HTML
<div class="social-cont">
<div class="social-cont1">
<img src="img/contact1.png" alt="contact1" width="21" height="30" />
</div> <!-- end social-cont1 -->
<div class="social-cont2">
<h6 class="social-context">Pastoor de Leijerstraat 29, 5246JA, Hintham</h6>
</div> <!-- end social-cont1 -->
</div> <!-- end social-cont -->
<div class="social-cont">
<div class="social-cont1">
<img src="img/contact3.png" alt="contact3" width="23" height="24" />
</div> <!-- end social-cont1 -->
<div class="social-cont2">
<h6 class="social-context">XXXXXXXXXXXXXX</h6>
</div> <!-- end social-cont1 -->
</div> <!-- end social-cont -->
CSS
.social-cont {
height: 100%;
width: 350px;
border-bottom: 1px solid #c1c1c1;
display: table;
background-color: salmon;
}
.social-cont1 img {
display: table-cell;
vertical-align: middle;
float: left;
}
h6.social-context {
display: table-cell;
vertical-align: middle;
color: #404040;
float: left;
}
这是在Coda中预览代码时得到的:
您不需要float: left
实际上,您不需要.social-cont1
和.social-cont2
,您可以设置img
和h6
样式
.social-cont1 {
display: table-cell;
vertical-align: middle;
}
.social-cont2 {
display: table-cell;
vertical-align: middle;
color: #404040;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.