gpt4 book ai didi

html - 在居中的两个 div 上重叠文本

转载 作者:太空狗 更新时间:2023-10-29 15:25:10 25 4
gpt4 key购买 nike

我正在尝试修改代码来做一些不同的事情,但我无法让它工作。这是代码:

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

这呈现:

enter image description here

使用这个 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 宽度非常小,文本就会错位,我的想法是将它相对于外部 div progress-bar 居中,所以它总是不管内部 div 是什么,但我不知道如何将文本放在顶部和中心,有什么想法吗?

最佳答案

试试这个 - DEMO

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;
}

关于html - 在居中的两个 div 上重叠文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13298287/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com