如何在 BootStrap 中创建一个与边缘有间距的进度条
Posted
技术标签:
【中文标题】如何在 BootStrap 中创建一个与边缘有间距的进度条【英文标题】:How To Create A ProgressBar With Spacing From The Edges In BootStrap 【发布时间】:2021-07-06 01:42:02 【问题描述】:我正在尝试创建一个与进度条边缘有一定间距的进度条。以下图片是我正在尝试创建的:
在上图中,灰色进度条中有一条红线,这就是我要创建的。
如何使用引导程序重新创建它
【问题讨论】:
【参考方案1】:尝试在进度条中添加一些边距,例如margin-left: 5%
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<title>Hello, world!</title>
</head>
<body>
<div class="container">
<div class="progress mt-3">
<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="progress mt-3">
<div class="progress-bar" role="progressbar" style="width: 25%; margin-left: 5%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="progress mt-3">
<div class="progress-bar" role="progressbar" style="width: 50%; margin-left: 5%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="progress mt-3">
<div class="progress-bar" role="progressbar" style="width: 75%; margin-left: 5%" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="progress mt-3">
<div class="progress-bar" role="progressbar" style="width: 100%; margin-left: 5%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
</div>
</div>
<!-- Optional javascript; choose one of the two! -->
<!-- Option 1: jQuery and Bootstrap Bundle (includes Popper) -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
<!-- Option 2: Separate Popper and Bootstrap JS -->
<!--
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.min.js" integrity="sha384-+YQ4JLhjyBLPDQt//I+STsc9iw4uQqACwlvpslubQzn4u2UU2UFM80nGisd026JF" crossorigin="anonymous"></script>
-->
</body>
</html>
【讨论】:
以上是关于如何在 BootStrap 中创建一个与边缘有间距的进度条的主要内容,如果未能解决你的问题,请参考以下文章
如何在 AMP 中创建类似 Bootstrap 的可折叠文件?
如何在 Bootstrap 5 中创建 jumbotron?
如何使用 NavWalker 和 bootstrap.min.css 在 WordPress 中创建 Bootstrap 导航栏