我想要做的是根据广告框中图像的高度垂直对齐计分框中的中间文本(h3)。我已经尝试了几种方法来使它起作用,但是到目前为止没有成功。我也很好奇如何将div与框大小(在我的情况下为.ads-box和.score-box)设置为相同的高度。提前致谢!

.current-scores {
  display: table;
  width: 100%;
  color: #ffffff;
  background-color: #01DFA5;
}
.current-scores .ads-box {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  width: 80%;
  text-align: center;
  padding: 8px 10px;
  margin: 0;
  float: left;
}
.current-scores .score-box {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  width: 20%;
  text-align: center;
  padding: 8px 10px;
  margin: 0;
  float: left;
}
.current-scores .score-box h3 {
  font-size: 16px;
  line-height: 18px;
  font-weight: bold;
  margin: 5px 0 0;
  padding: 0;
}


<div class="current-scores">
  <div class="ads-box">
    <img class="img-responsive" src="https://s3.amazonaws.com/images.seroundtable.com/google-mobile-app-ad-1347454342.png" />
  </div>
  <div class="score-box">
    <h3>IND Vs AUS</h3>
    <h3>IND - 153/0</h3>
  </div>
  <div style="clear:both;"></div>
</div>




Jsfiddle:http://jsfiddle.net/racy2408/6hu1gLtq/

最佳答案

更新了CSS .current-scores.current-scores .score-box

/*Current Scores and Schedules*/
.current-scores {
display: table;
/*position: fixed;
left: 0;
right: 0;
bottom: 0; */
overflow: hidden;
width: 100%;
color: #ffffff;
background-color: #01DFA5;
padding: 0;
margin: 0;
position:relative;
}
.current-scores .ads-box {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
width: 80%;
text-align: center;
padding: 8px 10px;
margin: 0;
float: left;
}
.current-scores .score-box {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
width: 20%;
text-align: center;
padding: 8px 10px;
margin: 0;
float: right;
position:absolute;
top:50%;
margin-top:-2em;
right:0px;
z-index:1000;
}
.current-scores .ads-box img {
width: 100%;
height: auto;
}
.current-scores .score-box h3 {
font-size: 16px;
line-height: 18px;
font-weight: bold;
margin: 5px 0 0;
padding: 0;
text-transform: uppercase;
text-shadow: -1px 2px 3px rgba(30, 30, 30, 0.8);
}

关于html - 如何在框大小div中垂直对齐中间文本?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28646370/

10-11 12:09