単一の文字が中央に配置されたスタイル付きボタンを作成しようとしています。
「border-image」と「border-width」を使用して、より大きなコンテンツに引き伸ばすことができるボタンを作成しています (この単純化されたシナリオではその機能が失われています...)。
私の問題は次のとおりです。ボタンが小さい場合 (具体的には、ボタンの幅が 2*border-width より少し大きい場合)、コンテンツが中央に配置されません。のような「従来の」テクニックを試してみましmargin: 0 auto;
たが、何の喜びも感じていないようです。これらの境界プロパティなしでクラスを使用すると、dumb-button
必要なものを取得できます (以下を参照)
これは問題をきちんと示しています。スタイル付きボタンの中央に文字を配置したい:
(Chrome/Safari で動作し、これは Webkit のみを対象としています) ( http://girliemac.com/blog/2011/07/29/five-css-tricks-used-in-enyoのテーマ ボタンの例)
私のCSSは次のとおりです。
.fancy-button {
border-image: url(http://girliemac.com/sandbox/images/alert-button.png) 0 14 111 14 fill repeat repeat;
border-width: 0 14px;
box-sizing: border-box;
font-size: 16px;
height: 37px;
line-height:37px;
text-align: center;
margin: 0 auto;
width: 28px;
}
.centerme {
position:relative;
margin:0 auto;
}
.dumb-button {
font-size: 16px;
height: 37px;
line-height: 37px;
text-align: center;
width: 28px;
background-color: red;
margin: 0 auto;
}
</p>
HTMLはこんな感じ。このクラスは、古い形の上にcenterme
新しいものを中心に据えようとする試みでした。div
それは私にはうまくいきません。バージョンはdumb-button
正しいように見えます(しかし鈍い...)
<div class="fancy-button">I</div>
<div class="fancy-button">W</div>
<div class="fancy-button"><div class="centerme">W</div></div>
<div class="dumb-button">I</div>
<div class="dumb-button">W</div>
<div class="dumb-button"><div class="centerme">W</div></div>
どんな助けでも大歓迎です。