【发布时间】:2017-08-10 00:11:15
【问题描述】:
我怎样才能简单地将h3 标记和p 标记显示在不同的行上,而h3 标记在顶部?
这段代码是一个更大项目的一部分,我知道还有其他方法可以将元素定位在不同的行的中心,但我不想影响它的父元素(更大的项目)并且想要使用更简单的弹性盒子。
.hover-over-windows-style {
height: 100%;
background: red;
/* Fails because h3 and p tags are not on separate lines */
display: flex;
align-items: center;
/* padding-top of 25% nearly works but content isnt in centre of parent div */
}
#parent {
height: 300px;
width: 300px;
}
<div id="parent">
<div class="hover-over-windows-style">
<h3><a href="matches/blitz.html">H3 Tag on top</a></h3>
<p>Paragraph here should be below the H3 tag, on a separate line. Not sure how to get this done. Setting 100% widths don't work and cannot display as block elements.</p>
</div>
</div>
【问题讨论】: