一定の(したがって自動ではなく再利用可能な)値をheight
またはline-height
に割り当てずに、背景イメージをテキストと垂直に整列させるのに問題があります。私は実際には、例えば、a
要素, with its text without assigning constant values to
行の高さの垂直方向の中心にbgイメージの方法があるのだろうかと思っていた `高`?背景とテキストを垂直方向に合わせる方法は?
ライブデモは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;
}
可能重複[divの内側の中央の画像を縦にする方法](http://stackoverflow.com/questions/2237636/how-to-vertically-center-image-inside- div) – JabberwockyDecompiler