使用固定高度的容器时,我只需简单地将行高属性与高度匹配即可。 未指定容器高度时如何操作?未指定父高度时的垂直居中文本
0
A
回答
1
有几种方法。这是表格方法。另一种方法是使父容器相对并使p标记绝对顶部:50%;. 如果您不支持ie8或更低版本,则可以使用flexbox。这里是一个很好的资源,了解Flexbox的:http://flexboxfroggy.com/
.container{
width: 300px;
height: 400px;
}
.content{
width: 100%;
height: 70%;
display: table;
}
p{
display: block;
display: table-cell;
vertical-align: middle;
}
<div class="container">
<div class="content">
<p>
Center text
</p>
</div>
</div>
1
#services .txt {
height: 500px;
border: 1px #000 solid;
display:table;
text-align:center;
}
.sub{
display:table-cell;
vertical-align:middle;
text-align:center;
}
<div id="services">
<div class="txt">
<div class="sub">
<h1>Lorem Ipsum</h1>
<p> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s..
</p>
</div>
</div>
</div>
现在试着改变的div .TXT高度,你会看到它的垂直定向的中心文本。
这种方式取决于使主分区显示:表;
and sub div display:table-cell;和vertical-align:middle;
0
.support-box {
width: 50%;
float: left;
display: block;
height: 20rem; /* is support box height you can change as per your requirement*/
background-color:#000;
}
.wrapper {
width: 50%;
display: block;
position: relative;
top: 50%;
transform: translateY(-50%);
background:#ddd;
margin:auto;
height:100px; /* here the height values are automatic you can leave this if you can*/
}
.text {
width: 100%;
display: block;
padding:10px;
margin:auto;
}
<div class="support-box">
<div class="wrapper">
<div class="text">USE OUR DESIGNS</div>
</div>
</div>
Js fiddle:// https://jsfiddle.net/vh4y426f/5/
+0
https://jsfiddle.net/vh4y426f/5/ –
相关问题
- 1. 垂直居中未知高度
- 2. 垂直居中未知长度的文本里面的文本
- 3. 当元素高度未知时垂直居中
- 4. 保持线高度垂直居中div没有固定高度
- 5. 居中水平和垂直文本的相对高度div
- 6. ImageMagick:垂直居中文本?
- 7. 垂直居中文本
- 8. CSS垂直居中文本
- 9. 垂直居中文本
- 10. css中的垂直文本高度
- 11. 垂直居中,未知高度,页面上的其他内容
- 12. 如何在已知高度的div内垂直居中未知高度的div?
- 13. 垂直居中线高
- 14. 垂直居中自动高度和最大高度的图像
- 15. 如何垂直居中固定位置的文本跨度?
- 16. 垂直居中与固定高度标题中的CSS
- 17. BlackBerry垂直居中自定义高度的LabelField
- 18. 居中水平和垂直的DIV没有固定高度
- 19. 垂直高度的CSS文本
- 20. 计算SVG文本的垂直高度
- 21. 标签中的垂直居中文本
- 22. 在div中垂直居中的文本
- 23. 垂直居中单一和多行CSS没有固定高度
- 24. WPF:DatePicker的文本垂直居中
- 25. 在div中垂直居中文本?
- 26. jquery masonry中垂直居中文本
- 27. 在UILabel中垂直居中文本
- 28. 在父行中垂直居中图像
- 29. 更改div的顺序与动力高度CSS,文本垂直居中对齐
- 30. 垂直居中
'垂直对齐:基线|长度|分|超级|顶|文顶|中部|底部|文本底部|初期|继承;' –