我目前有这个结果:
但它应该是这样的:
m 和 s 应该与底部对齐。
我的代码:
.right-timer-area {
width: 128px;
height: 52px;
line-height: 52px;
font-size: 36px;
font-weight: 300;
color: #ffa000;
float: right;
margin: 0 50px 0 0;
}
.right-timer-area > span.timer-centered {
height: 36px;
display: inline-block;
vertical-align: middle;
}
.right-timer-area > span.timer-centered span {
display: inline-block;
float: left;
line-height: 1;
vertical-align: bottom;
}
.right-timer-area .timer-sm {
font-size: 16px;
}
<div class="right-timer-area">
<span class="timer-centered">
<span class="timer-big">15</span>
<span class="timer-sm">m</span>
<span>-</span>
<span class="timer-big">45</span>
<span class="timer-sm">s</span>
</span>
</div>
但它没有用。是否有任何解决方法,而不更改.right-timer-area
(它位于其他div
内并且没有table-layout
)?
如果是,那怎么办?
答案 0 :(得分:5)
您的问题是您已将float: left;
添加到.right-timer-area > span.timer-centered span
。这会覆盖display: inline-block;
,表示vertical-align
无效。要获得所需的结果,请进行以下更改:
float: left;
.right-timer-area > span.timer-centered span
.right-timer-area .timer-sm
更改为.right-timer-area > span.timer-centered .timer-sm
以使其更具体。这可确保它覆盖.right-timer-area > span.timer-centered span
vertical-align: sub;
添加到.right-timer-area > span.timer-centered .timer-sm
span
之间的空白,删除实际空格,将font-size
timer-centered
缩减为0
或使用评论技巧
.right-timer-area {
clear: right;
width: 128px;
height: 52px;
line-height: 52px;
font-size: 36px;
font-weight: 300;
color: #ffa000;
float: right;
margin: 0 50px 0 0;
}
.right-timer-area > span.timer-centered {
height: 36px;
display: inline-block;
vertical-align: middle;
}
.right-timer-area > span.timer-centered span {
display: inline-block;
line-height: 1;
vertical-align: bottom;
}
.right-timer-area > span.timer-centered .timer-sm {
font-size: 16px;
vertical-align: sub;
}
.right-timer-area .fontsize {
font-size: 0;
}
.right-timer-area span.fontsize span {
font-size: 36px;
vertical-align: baseline;
}
&#13;
<div class="right-timer-area">
<span class="timer-centered">
<span class="timer-big">15</span><span class="timer-sm">m</span><span>-</span><span class="timer-big">45</span><span class="timer-sm">s</span>
</span>
</div>
<div class="right-timer-area">
<span class="timer-centered fontsize">
<span class="timer-big">15</span>
<span class="timer-sm">m</span>
<span>-</span>
<span class="timer-big">45</span>
<span class="timer-sm">s</span>
</span>
</div>
<div class="right-timer-area">
<span class="timer-centered">
<span class="timer-big">15</span><!--
--><span class="timer-sm">m</span><!--
--><span>-</span><!--
--><span class="timer-big">45</span><!--
--><span class="timer-sm">s</span>
</span>
</div>
&#13;
答案 1 :(得分:3)
您可以使用display: table-cell
并从float: left
移除.right-timer-area > span.timer-centered span
:
.right-timer-area {
width: 128px;
height: 52px;
line-height: 52px;
font-size: 36px;
font-weight: 300;
color: #ffa000;
float: right;
margin: 0 50px 0 0;
}
.right-timer-area > span.timer-centered {
height: 36px;
display: inline-block;
vertical-align: middle;
}
.right-timer-area > span.timer-centered span {
display: table-cell;/*change to table-cell*/
line-height: 1;
vertical-align: bottom;
}
.right-timer-area .timer-sm {
font-size: 16px;
}
&#13;
<div class="right-timer-area">
<span class="timer-centered">
<span class="timer-big">15</span>
<span class="timer-sm">m</span>
<span>-</span>
<span class="timer-big">45</span>
<span class="timer-sm">s</span>
</span>
</div>
&#13;
答案 2 :(得分:1)
你可以这样试试 -
.right-timer-area {
/*width: 128px;*/
height: 52px;
line-height: 52px;
font-size: 36px;
font-weight: 300;
color: #ffa000;
float: right;
margin: 0 50px 0 0;
display: table;
}
.right-timer-area > span.timer-centered {
height: 36px;
display: inline-block;
vertical-align: middle;
display: table-row;
}
.right-timer-area > span.timer-centered span {
display: inline-block;
/*float: left;*/
line-height: 1;
vertical-align: bottom;
display: table-cell;
}
.right-timer-area .timer-sm {
font-size: 16px;
}
&#13;
<div class="right-timer-area">
<span class="timer-centered">
<span class="timer-big">15</span>
<span class="timer-sm">m</span>
<span>-</span>
<span class="timer-big">45</span>
<span class="timer-sm">s</span>
</span>
</div>
&#13;
我希望它会对你有所帮助。