这就是我需要的
是否可以将标题置于两个可以具有不同大小的div之间?没有JS。
<div class="parent">
<div class="subtitle">Subtitle</div>
<h2>Title</h2>
<div class="subtitle">Subtitle</div>
</div>
我检查了Stretch (vertically) middle div between the other two,但在我的情况下,我不知道max-height
header
,footer
。
答案 0 :(得分:0)
这就是flex的用途,假设您不必支持旧浏览器。请参阅can I use。
.parent {
position: relative;
background: black;
color: white;
min-height: 100px;
display:flex;
flex-direction: column;
align-content: space-between;
padding: 0 40px;
border: 1px solid white;
width: calc(33% - 90px);
float:left;
}
.parent:before {
content: " ";
position: absolute;
top: 50%;
left: 0;
right: 0;
height: 1px;
background: red;
}
.parent h2 {
position: absolute;
top: 50%;
margin: 0;
transform: translateY(-50%);
}
.subtitle {
padding: 40px 0;
}
&#13;
<div class="parent">
<div class="subtitle">Subtitle</div>
<h2>Title</h2>
<div class="subtitle">Subtitle</div>
</div>
<div class="parent">
<div class="subtitle">Subtitle<br/>Subtitle<br/>Subtitle</div>
<h2>Title</h2>
<div class="subtitle">Subtitle</div>
</div>
<div class="parent">
<div class="subtitle">Subtitle</div>
<h2>Title long<br/>2 lines</h2>
<div class="subtitle">Subtitle</div>
</div>
&#13;