bootstrap-4 - ng-bootstrap 1.0 - 进度条居中值

标签 bootstrap-4 ng-bootstrap

我们正在使用 ng-bootstrap 的进度条,并希望将值文本置于整个进度条的中心,而不是使其置于绿色进度区域的中心。

编辑:我的意思是图像,需要红色框所在的值。 enter image description here

到目前为止,我所拥有的是以下内容,但不起作用:

.progress-text {
    color: #000;
    font-weight: 700;
    position: absolute;
    display: block;
    width: 100%;
}

<ngb-progressbar type="success" showValue="false" [value]="data?.progress" [striped]="false" [animated]="false">
    <span class="progress-text">{{data?.progress}}%</span>
</ngb-progressbar>

关于我做错了什么有什么想法吗?

最佳答案

这是您在这种情况下需要的自定义 CSS(我最初误解了您的要求):

.progress-text {
    color: #000;
    font-weight: 700;
    position: absolute;
    display: block;
    left: 49%; /* just in case calc is unavailable in a browser */
    left: calc(50% - 12px);
}

这是一个有效的示例:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">

<style>
.progress-text {
    color: #000;
    font-weight: 700;
    position: absolute;
    display: block;
    left: 49%; /* just in case calc is unavailable in a browser */
    left: calc(50% - 12px);
}
</style>

<div class="container">
    <div class="row">
        <div class="col">
            <div class="progress mt-5">
                <div class="progress-bar" role="progressbar" style="width: 25%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">
                    <span class="progress-text">25%</span>
                </div>
            </div>
        </div>
    </div>
</div>

关于bootstrap-4 - ng-bootstrap 1.0 - 进度条居中值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48303795/

相关文章:

angular - 请问ng-bootstrap 支持bootstrap4 的新功能卡吗?

javascript - Angular NgbModal beforeDismiss 不起作用

javascript - 如何访问 ngfor 中 Angular 2 中生成的 Accordion 列表中的特定 Accordion

css - 如何降低 Bootstrap 4 中的导航栏高度?

css - Bootstrap 4 :How to make page to run in responsive

angular - ng-bootstrap 中轮播的图像缩略图

angular - 自定义 NgbModal 大小

css - 如何将 toastr-rails gem 添加到 Rails 6 元素中?

angular - Angular/Bootstrap 中的卡片

html - 如何在带有网格的 Bootstrap 中设置中间和底部文本