我似乎无法让图像和文本在主 div 内垂直对齐。
https://jsfiddle.net/jf2dgh0j/
.image {
width:50%;
height:auto;
float:right;
vertical-align:middle; }
最佳答案
我不确定为什么你在父 div 的顶部有 200 像素的填充,但以下可能是你想要实现的。
将 display: table-cell
应用于 .description-wrap
和 .image
子元素。
.work-subwrap {
width:70%;
background-color:#C87778;
margin:0 auto;
margin-top:30px;
display:table;
}
.description-wrap, .image {
display: table-cell;
width: 50%;
vertical-align: middle;
text-align: center;
}
.description-wrap a {
display: inline-block;
padding: 10px;
background-color: white;
}
.image img {
width:100%;
vertical-align: top;
}
<div class="work-subwrap">
<div class="description-wrap"> <a class="project-link" href="#modal1">Maru</a></div>
<div class="image">
<img alt="" id="first" src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcQdiIK0bVvSbRnegxQPMS6V0nBHFT40j6P6OH-C11pmooy6Duad">
</div>
</div>
关于css - 垂直对齐 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31505951/