我很难垂直对齐'h1‘红色通知气泡与它旁边的'h2’标签。我是在正确的轨道上尝试使用display: inline-block;还是完全关闭。我也尝试过使用vertical-align:middle,但这似乎行不通。任何帮助都将不胜感激,谢谢。
body {
font-family: sans-serif;
}
.steps h2 {
font-weight: 400;
text-transform: uppercase;
font-size: 20px;
margin-left: 10px;
margin-bottom: 10px;
letter-spacing: 1px;
display: inline-block;
}
h1 {
color: #fff;
font-size: 40px;
font-weight: 100;
}
ul {
list-style: none;
margin: 0;
padding: 0;
}
.steps {
width: 100%;
height: 405px;
position: absolute;
top: 9%;
left: 0px;
right: 0px;
margin: 0px auto;
}
label {
background: #F2F2F2;
height: 69px;
width: 100%;
display: inline-block;
border-bottom: 1px solid #2C3E50;
color: #fff;
text-transform: capitalize;
font-weight: 900;
font-size: 11px;
letter-spacing: 1px;
position: relative;
padding: 5px 5px 5px 20px;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
label h2 span {
display: block;
font-size: 12px;
text-transform: capitalize;
font-weight: normal;
color: #bdc3c7;
padding-top: 5px;
}
.new {
width: 30px;
height: 30px;
display: inline-block;
border-radius: 50%;
font-size: 20px;
color: #fff;
line-height: 30px;
text-align: center;
background: #FF4447;
}<div class="steps">
<h2>Your Matches</h2>
<ul id="matches">
<li>
<h1 class="new">1!</h1>
<label for="label-1">
<h2>Steve, 28 <span>Matched 2 days ago</span></h2>
</label>
</li>
<li>
<label for="label-2">
<h2>Tony, 30 <span>Matched 1 hour ago</span></h2>
</label>
</li>
<li>
<label for="label-3">
<h2>Bruce<span>Matched 4 days ago</span></h2>
</label>
</li>
</ul>
</div>
发布于 2016-06-04 03:50:16
就像这样?

如果是这样的话,你的思路是正确的。前面提到的解决方案的另一个替代方案是将h1移动到label中,在其中,您希望它旁边的h1 (基本上是标签的内容)作为子元素在实际的label元素中移动。您还需要将label h2 span更改为display: inline;。
(HTML)
<li>
<label for="label-1">
<h1 class="new">1!</h1>
<h2>Steve, 28 <span>Matched 2 days ago</span></h2>
</label>
</li>(CSS)
label h2 span {
display: inline;
font-size: 12px;
text-transform: capitalize;
font-weight: normal;
color: #bdc3c7;
padding-top: 5px;
}
.new {
width: 30px;
height: 30px;
display: inline-block;
border-radius: 50%;
font-size: 20px;
color: #fff;
line-height: 30px;
text-align: center;
background: #FF4447;
}发布于 2016-06-04 04:01:25
我不确定我是否理解你想要做的事情,但以下是我的快速解决方案:
您可以通过将其添加到CSS中来设置元素位置:
h1 {
position: relative;
z-index: 9999;
top: 4rem;
left: 10rem;
}DEMO
https://stackoverflow.com/questions/37626076
复制相似问题