难以将 h1 和 h2 与 CSS 对齐
Difficulty aligning h1 and h2 with CSS
我很难将 '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>
如果是这样,那么您的思路是正确的。前面提到的解决方案的另一种替代方法是将 h1
移动到 label
中,您想要它旁边的 h1
(基本上是标签的内容)在实际 label
元素,作为 child。您还需要将 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;
}
我不确定我是否理解您的意图,但这是我的快速解决方案:
您可以通过将此添加到您的 CSS:
来设置元素位置
h1 {
position: relative;
z-index: 9999;
top: 4rem;
left: 10rem;
}
我很难将 '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>
如果是这样,那么您的思路是正确的。前面提到的解决方案的另一种替代方法是将 h1
移动到 label
中,您想要它旁边的 h1
(基本上是标签的内容)在实际 label
元素,作为 child。您还需要将 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;
}
我不确定我是否理解您的意图,但这是我的快速解决方案:
您可以通过将此添加到您的 CSS:
来设置元素位置h1 {
position: relative;
z-index: 9999;
top: 4rem;
left: 10rem;
}