【发布时间】:2014-10-16 22:52:53
【问题描述】:
我正在建立一个平面设计的网站。我有一个标题,在它下面有两个相邻的不同颜色的块。我试过左右浮动,但建议使用 display: inline-block 代替。
不过,我遇到了一个问题。我想在左右块的中间放置一些文本并尝试使用 align-items: center,但发现只有当 div 设置为 flex 时才有效。
所以我的问题是,我能否以某种方式保留我的内联块并使我的文本居中在我的块中间(水平和垂直)?
body {
margin: 80px 0 0;
}
#pagewrapper {
width: 100%;
}
#header {
width: 100%;
height: 80px;
background-color: #008B8B;
position: fixed;
top: 0;
}
.content-left,
.content-right {
width: 50%;
height: 500px;
color: #FFFFFF;
display: -moz-inline-stack;
display: inline-block;
zoom: 1;
*display: inline;
}
.content-left {
background-color: #66CC99;
}
.content-right {
background-color: #20B2AA;
}
#header-bot {
height: 800px;
background-color: #F8F8FF;
}
#footer {
height: 50px;
background-color: #AFEEEE;
}
.title {
font-size: 18px;
}
<body>
<div id="pagewrapper">
<div id="header">
</div>
<!-- End of Header -->
<div class="content-left">
<span class="title">This is left Content</span>
</div>
<!-- End of Content Left -->
<div class="content-right">
<span class="title">This is Right Content</span>
</div>
<!-- End of Content Right -->
<div id="header-bot">
</div>
<!-- End of Header-Bot -->
<div id="footer">
</div>
<!-- End of Footer -->
</div>
<!-- End of PageWrapper -->
</body>
【问题讨论】:
标签: html alignment vertical-alignment css