问题
I can get a pill badge using this method (found here & jsfiddle here):
<span class="badge badge-pill badge-primary" style="float:right;margin-bottom:-10px;"> </span>
How can I decrease the size of the dot? (note, I tried wrapping the <span>
in <p>
but that messed up formatting and didn't change the size of the dot)
回答1:
According to the documentation:
Badges scale to match the size of the immediate parent element by using relative font sizing and em units.
So if u change the font size of the parent element or the font size of the span itself, your badge size will change too
Here is an exaple
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<h1>
<span class="badge badge-pill badge-primary"> </span>
</h1>
<h2>
<span class="badge badge-pill badge-primary"> </span>
</h2>
<h3>
<span class="badge badge-pill badge-primary"> </span>
</h3>
<span class="badge badge-pill badge-primary" style="font-size: 5px;">
</span>
<span class="badge badge-pill badge-primary" style="font-size: 10px;">
</span>
<span class="badge badge-pill badge-primary" style="font-size: 15px;">
</span>
<span class="badge badge-pill badge-primary" style="font-size: 20px;">
</span>
回答2:
From the question what I feel is you need something like this. No need of any custom classes, if you need more customization use the second example
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
Inbox<sup><span class="badge badge-pill badge-primary">10</span></sup>
It should be possible by overriding the class. You can also do this by editing the bootstrap sass files. Check this if it works for you.
.badge.badge-pill.badge-primary.pill-small {
padding:2px;
font-size:.5rem;
}
.badge.badge-pill.badge-primary.pill-medium {
padding:7px;
font-size:.75rem;
}
.badge.badge-pill.badge-primary.pill-large {
padding:7px;
font-size:1.5rem;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<span class="badge badge-pill badge-primary pill-small">2</span>
<span class="badge badge-pill badge-primary pill-medium">100</span>
<span class="badge badge-pill badge-primary pill-large">19</span>
来源:https://stackoverflow.com/questions/64633073/change-the-size-of-a-bootstrap-pill-badge