是否可以堆叠行内块元素?
我有一个 DIV,我希望其中的元素(h1 和 P)居中。所以我将 DIV 设置为 text-align center 并将 H1 和 P 标签分别设置为 inline-blocks。
想法是将两个元素(H1 和 P)显示为行内块元素,以便内容居中,并且在文本长度的背景中显示透明 png。
但是我遇到的问题是,将元素作为内联块意味着它们将彼此相邻出现(我不希望这种情况发生),所以我将 P 标签设置为块元素,但它导致透明 png 为宽的。
HTML:
<div id="hero">
<div class="container">
<div class="row">
<div class="span12" id="hero-text">
<h2>Heading line</h2>
<p>Paragraph line goes here</p>
</div>
</div>
</div>
</div>
CSS
#hero {
height: 435px;
width: 100%;
background: url(../img/hero-image.png) 0 0 no-repeat;
background-color: #999;
position: relative;
color: #FFF;
border-bottom: 3px solid #E6E6E6;
}
#hero-text {
position: absolute;
top: 33%;
text-align: center;
}
#hero h2 {
font-size: 4em;
font-style: normal;
line-height: 50px;
padding-top: 10px;
background: url(../img/bg-heading.png) repeat;
display: inline-block;
padding: 10px 20px;
}
#hero p {
font-size: 2em;
line-height: 30px;
display: block;
background: url(../img/bg-heading.png) repeat;
padding: 10px 20px;
}
任何帮助表示赞赏。