[英]How to vertically align a div to the center with respect to the parent div
How do I vertically align a div
with respect to the parent div
? 如何将div
相对于父div
垂直对齐?
<div class="col-xs-12 pr30 parentdiv">
<div class="image-content col-xs-9 col-md-5 pull-right pl0 pr0 ml0" style="margin-right:6% !important;">
<div class="pull-left">
<a href="productbanner.html">
<img height="100%" width="100%" alt="Liberty Global logo" src="productbanner.JPG" class="img-responsive pull-left">
</a>
</div>
</div>
<div class="text-content col-xs-12 col-md-6 pull-left">
<div>
<div class="heading-content">
<span class="textDecreaseCaption">
<a href="productbanner.html">Product Banner</a>
</span>
</div>
<div class="smallspace"></div>
<div class="description-content textDecrease">
Product details banner with image component
</div>
</div>
</div>
This is the HTML I have included. 这是我包含的HTML。 The parent div
takes the size of the image-content. 父div
采用图像内容的大小。 I want the div
"text-content" to be aligned to the center of the parent div, that is to the center of the image-content div
. 我希望div
“文本内容”与父div的中心对齐,即与图像内容div
的中心对齐。
I tried this logic 我尝试了这种逻辑
.parentdiv {
display: table;
}
.text-content {
display: table-cell;
vertical-align: middle;
}
There's no change in the vertical alignment in this case. 在这种情况下,垂直对齐方式没有变化。 Please provide me a solution for this issue. 请为我提供此问题的解决方案。
Seems to work as it, maybe another css is applied. 似乎可以正常工作,也许应用了另一个CSS。 See http://codepen.io/adrienmar/pen/PNWYMw 见http://codepen.io/adrienmar/pen/PNWYMw
.parentdiv {
display: table;
}
.text-content {
display: table-cell;
vertical-align: middle;
}
Try this 尝试这个
.parentdiv {
position:relative;
}
.text-content {
position:absolute;
top:50%;
transform: translateY(-50%);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.