我无法将背景图像与文本垂直对齐,而没有为height
or分配常量(因此,不是自动和可重用)值line-height
。我想知道是否真的有一种方法可以垂直居中对齐 bg 图像,比如a
元素, with its text without assigning constant values to
行高or
?
现场演示可在此处获得:http ://cssdesk.com/8Jsx2 。
这是HTML:
<a class="">background-position: center</a>
<a class="contain">background-size: contain</a>
<a class="line-height">Constant line-height</a>
这是CSS:
a {
display: block;
margin: 10px;
width: 200px;
padding-left: 34px;
font-size: 14px;
background: url('http://cdn1.iconfinder.com/data/icons/freeapplication/png/24x24/Thumbs%20up.png');
background-repeat: no-repeat;
background-position: 5px center;
border: 1px solid black;
}
/* I don't want to use constant line-height */
.line-height {
line-height: 24px;
}
/* I don't want to use this, because I want my bg image's size to stay intact */
.contain {
background-size: contain;
}