Card with only one paragraph element in the card-body has unnecessary margin at the bottom
See original GitHub issueWhen a bootstrap card only contains one paragraph element <p> in its card-body, then the paragraph still has its default margin-bottom: 1rem; This should be removed for the last(!) paragraph in a card.
Simple example HTML
<div class="card">
<div class="card-body">
<p>This paragraph has a default margin-bottom. It shouldn't</p>
</div>
</div>
Solution
Add the following CSS
.card-body p:last-child {
margin-bottom: 0;
}
JSFiddle
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Remove extra space from a Bootstrap 4 Card - Stack Overflow
This card div is 80% of the column div. As it defaults to the left side, the remaining 20% appears on the right...
Read more >Bootstrap Card Component: a Complete Introduction - SitePoint
This component is built on top of Flexbox, and you can use the Bootstrap spacing utility classes for margins and padding. Cards can ......
Read more >Cards | USU Template
A paragraph tag is not required inside the card body, and if it is used, ... the last paragraph in the card to...
Read more >Cards - Lightning Design System
To initialize a card, apply the slds-card class to an <article> element. ... If the card header icon is redundant with the card...
Read more >Card | Components - BootstrapVue
With sub-component <b-card-text> , paragraph text can be added to the card. The last <b-card-text> in the card body will have its bottom...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

There is already a class
card-textfor it. Or you can use utility classmb-0.https://github.com/twbs/bootstrap/blob/c7bc7a31bbc11c3f9af3ad317581cbd13c7bb5f1/scss/_card.scss#L62-L64
And what if the last item is an
.alertfor instance? Since.alerthas a bottom margin it will be the same issue. Same for many more components. IMHO, you should use margin utilities, as @rohit2sharma95 said.