我在对齐<label>
放置在div中的a时遇到问题。
这是我的HTML:
<div class="one-whole index-border">
<div class="score red score--primary">
<label>20</label>
</div>
</div>
这是我的CSS:
.one-whole {
100%;
}
.index-border {
border-bottom: 2px solid #D2D2D2;
}
.score {
border: none;
display: inline-block;
/* margin: 0; */
line-height: 1;
width: 120px;
height: 100px;
text-align: center;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
-ms-border-radius: 6px;
-o-border-radius: 6px;
border-radius: 6px;
-webkit-box-shadow: 0 0 4px rgba(51, 51, 51, 0.125);
-moz-box-shadow: 0 0 4px rgba(51, 51, 51, 0.125);
box-shadow: 0 0 4px rgba(51, 51, 51, 0.125);
color: white;
margin-bottom: 15px;
vertical-align: middle;
}
.red {
background: #CC0000;
background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #FF3400), color-stop(100%, #CC0000));
background-image: -webkit-linear-gradient(#FF3400, #CC0000);
background-image: -moz-linear-gradient(#FF3400, #CC0000);
background-image: -o-linear-gradient(#FF3400, #CC0000);
background-image: linear-gradient(#FF3400, #CC0000);
}
.score--primary {
border: 1px solid #CC0000;
font-size: 30px;
font-weight: bold;
}
我以为可以使用vertical-align: middle
,但是没有运气。
这是一个小提琴:http : //jsfiddle.net/oampz/aH86E/
如果有什么办法可以重构我的代码,那将会有所帮助。
谢谢
您需要display: table-cell;
代替使用 display: inline-block;
.score {
/* Other properties */
display: table-cell;
}
至于代码的重构的话,你可以安全地删除专有特性box-shadow
,box-radius
以及渐变码,现在它取决于你,直到什么水平你想支持旧版浏览器。
重构CSS
.one-whole {
100%;
}
.index-border {
border-bottom: 2px solid #D2D2D2;
}
.score {
border: none;
display: table-cell;
/* margin: 0; */
line-height: 1;
width: 120px;
height: 100px;
text-align: center;
border-radius: 6px;
box-shadow: 0 0 4px rgba(51, 51, 51, 0.125);
color: white;
margin-bottom: 15px;
vertical-align: middle;
}
.red {
background-image: linear-gradient(#FF3400, #CC0000);
}
.score--primary {
border: 1px solid #CC0000;
font-size: 30px;
font-weight: bold;
}
另外,我刚刚看到您正在使用rgba()
它,因此最好为此声明一个回退,所以使用,
.score {
/* Other properties */
box-shadow: 0 0 4px #333; /*Equivalent to rgb(51,51,51) */
box-shadow: 0 0 4px rgba(51, 51, 51, 0.125);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句