question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Card with only one paragraph element in the card-body has unnecessary margin at the bottom

See original GitHub issue

When 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

https://jsfiddle.net/qhv016wa/

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
rohit2sharma95commented, Jul 22, 2020

There is already a class card-text for it. Or you can use utility class mb-0.

https://github.com/twbs/bootstrap/blob/c7bc7a31bbc11c3f9af3ad317581cbd13c7bb5f1/scss/_card.scss#L62-L64

1reaction
florianlacreusecommented, Jul 22, 2020

And what if the last item is an .alert for instance? Since .alert has a bottom margin it will be the same issue. Same for many more components. IMHO, you should use margin utilities, as @rohit2sharma95 said.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found