在 jQuery 中向进度条添加文本
是否有一些调整可以向进度条控件添加标题?我很乐意放置一个显示当前百分比的居中标题。
Is there some tweak to add a caption to the progressbar control? I'd love to put a centered caption which displays current percentage.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您只需添加带有一些样式的
即可在下方获得居中标题,如下所示:
以及一些 CSS:
您可以在这里尝试一下,只需使用
$("#progressbar .caption").html(value)
来更新它。You can just add a
<div>
with some styling to get a centered caption underneath, like this:And some CSS:
You can give it a try here, just use
$("#progressbar .caption").html(value)
to update it.这更多的是一个 CSS 问题。我已经将标签直接置于进度条上方。我这样做的方法是:
将进度条代码包装在
div
中,并在容器末尾有一个清除div
。然后,在容器中添加标签并将其浮动
到左侧。在标签中添加一些空间,这样它就不会接触进度条的侧面:实例化进度条,标签应该浮动在进度条中,向左一点。您必须调整元素的填充和宽度/高度,以使其浮动到您想要的位置。 (例如,像栏的中心)
在这里尝试。正如您从我的 CSS 代码中看到的,需要稍微调整一下才能将其居中,但看起来不错。
This is more a CSS question. I've gotten the label to be centered directly over the progress bar. The way I've done it is to:
Wrap your progress bar code in a
div
with a clearingdiv
at the end of the container. Then, prepend your label in the container andfloat
it to the left. Add some space in the label so it's not touching the side of the progress bar:Instantiate the progress bar and the label should be floating in the progress bar, to the left a little. You will have to play with padding and width/height of the elements to get it to float where you want it. (Like the center of the bar, for example)
Try it here. As you can see from my CSS code, it takes a little fiddling to center it just right, but it looks nice.
试试这个,很简单:
CSS:
Try this, it's quite simple:
CSS: