【发布时间】:2017-07-03 16:43:34
【问题描述】:
试图使choice_result_text 在中间垂直对齐。 span 成功垂直对齐在中间,但不是 p。任何想法?代码:
.poll_results .choice_result {
margin-bottom: 3px;
height: 42px;
width: 100%;
}
.poll_results .choice_result p.choice_result_text {
float: left;
height: 39px;
background-image: linear-gradient(#4d4d4d, #262626);
position: relative;
top: 50%;
transform: translateY(-50%);
width: 30%;
color: #fff;
font-size: 15px;
border-radius: 2px 0 0 2px;
text-align: center;
border: 1px solid #333;
}
.choice_result_middle {
float: left;
height: 39px;
background-image: linear-gradient(#3366cc, #1f3d7a);
position: relative;
top: 50%;
transform: translateY(-50%);
min-width: 30%;
color: #fff;
font-size: 15px;
border-radius: 0 2px 2px 0;
text-align: left;
border: 1px solid #333;
margin-right: 7px;
border-left: none;
}
.poll_results .choice_result span {
float: left;
position: relative;
top: 50%;
transform: translateY(-50%);
}
<div class="poll_results">
<div class="choice_result" data-choice_percent="10">
<p class="choice_result_text">Yes</p>
<p class="choice_result_middle"></p>
<span>10%</span>
</div>
<div class="choice_result" data-choice_percent="35">
<p class="choice_result_text">No</p>
<p class="choice_result_middle"></p>
<span>35%</span>
</div>
<div class="choice_result" data-choice_percent="54">
<p class="choice_result_text">Yet to see</p>
<p class="choice_result_middle"></p>
<span>54%</span>
</div>
<p class="total_votes">Total Votes: 0</p>
</div>
【问题讨论】:
-
是的,使用
display: table-cell搞砸了一切 -
哦,等等,我试过
line height,它成功了。不用担心,谢谢。