7

少し違うことをするようにコードを変更しようとしていますが、動作させることができません。これはコードです:

<div id="progress-bar" class="all-rounded">
<div id="progress-bar-percentage" class="all-rounded" style="width: 88%">88/100</div>
</div>

これは以下をレンダリングします:

ここに画像の説明を入力

この CSS の使用:

.all-rounded {
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
}

.spacer {
    display: block;
}

#progress-bar {
    width: 100px;
    background: #cccccc;
}

#progress-bar-percentage {
    background: #3063A5;
    padding: 5px 0px;
    color: #FFF;
    text-align: center;
}

テキスト88/100が内側の div 内に印刷されているprogress-bar-precentageため、この div に対して中央に配置されていることがわかります。これの問題は、progress-bar-precentage幅が非常に小さい場合、テキストがずれてしまうことです。私の考えは、外側のdivprogress-barなので、内側のdivに関係なく常に配置されますが、テキストを上部と中央に配置する方法がわかりません。アイデアはありますか?

4

2 に答える 2

18

これを試してください -デモ

HTML

<div id="progress-bar" class="all-rounded">
    <div id="progress-bar-percentage" class="all-rounded" style="width: 68%"><span>68/100</span></div>
</div>

CSS

#progress-bar {
    width: 100px;
    background: #cccccc;
    position: relative;
}

#progress-bar-percentage {
    background: #3063A5;
    padding: 5px 0px;
    color: #FFF;
    text-align: center;
    height: 20px;
}

#progress-bar-percentage span {
    display: inline-block;
    position: absolute;
    width: 100%;
    left: 0;
}
于 2012-11-08T21:50:58.500 に答える
0

次のようなことを試してください:

<div id="progress-bar" class="all-rounded">
<div id="progress-bar-percentage" class="all-rounded" style="width: 88%"></div>
<div id="progress-bar-text">88/100</div>
</div>

.all-rounded {
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
}

.spacer {
    display: block;
}

#progress-bar {
    width: 100px;
    background: #cccccc;
    position: relative;
}

#progress-bar-percentage {
    background: #3063A5;
    padding: 5px 0px;
    position: absolute;
    top: 0;
    left: 0;
}

#progress-bar-text {
    width: 100%;
    color: #FFF;
    text-align: center;
    position: absolute;
    top: 0;
    left: 0;
}
于 2012-11-08T21:51:05.977 に答える