我有一个问题,让文本出现在屏幕中间(高度)在网页上。该网站的HTML是:中央对齐的元素CSS没有flexbox
<html lang="en">
<head>
<title>example</title>
<link href="example.css" rel="stylesheet">
</head>
<body>
<div class="home-container">
<div class="home-row">
<div class="some-other-class">
<p>text that should be in the middle</p>
</div>
</div>
</div>
</body>
</html>
我想要做的是有家庭容器元一路延伸到页面的底部,并有text that should be in the middle
在它的中间。我css
样子:
html, body{
height:100%;
}
.home-container{
width: 100%;
height: 100%;
background-color: rgba(139,0,0,0.4);
}
.home-row{
vertical-align: middle;
}
我明白,我想要做的是可能的,如果我反而让home-container
像这样:
.home-container{
width: 100%;
height: 100%;
background-color: rgba(139,0,0,0.4);
align-items: center;
display: flex;
}
但这并不对所有的浏览器。我在做什么错了vertical-align
属性?标识是不是真的做任何事情在我的例子...
,以便能够使用'垂直对齐'你需要在大容器(.home-container)上使用'display:table'和'.home-row'上的display:table-cell' –
使用CSS表和定位属性:http://stackoverflow.com/a/31977476/3597276 –