Is there a potential spacing issue in Bootstrap 4?

Utilizing Bootstrap 4's Spacing Utilities, you can easily adjust margins and paddings through simple CSS classes.

In theory, it should be possible to achieve something like this:

<div class="d-inline-block bg-inverse p-5 pb-0 m-5 mb-0"></div>

This element should have paddings and margins on each side, with the exception of the bottom. Right?

However, instead of that happening, the pb-0 and mb-0 are being overridden by p-5 and

m-5</code, as illustrated in this example:
<a href="https://jsfiddle.net/80dssmxh/" rel="nofollow noreferrer">JSFiddle demo</a>.</p>

<hr>

<p>The <code>pb-0
and mb-0 classes come after p-5 and m-5 in the original source code, and all attributes in these classes have !important. Therefore, pb-0 should override the padding-bottom defined by p-5, and mb-0 should override the margin-bottom defined by m-5.

I have created another example where I defined these classes in the same manner, and they work as intended: comparison demo in JSFiddle.


Why aren't these Bootstrap 4 classes behaving as expected?

Answer №1

The spacing utilities in this code snippet are using !important, so simply trying to use pb-0 to override p-5 will not be effective due to the order of declaration in the bootstrap.css file.

To achieve the desired outcome, follow this link for a solution that involves setting specific sides...

<div class="d-inline-block bg-inverse pb-0 px-5 pt-5 mb-0 ml-5 mt-5"></div>

Additionally, since the DIV element does not have padding or margins by default, omitting the *-0 would suffice...

<div class="d-inline-block bg-inverse px-5 pt-5 ml-5 mt-5"></div>

For further reference, visit this link.


Another helpful resource on understanding when it is appropriate to utilize !important: When Using !important Is the Right Choice

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When attempting to call the event outside of the component, the functionality of the event in VUE.js does not work

Currently, I am working on a small product page following the guidelines from this Vue.js tutorial. The page consists of a product component which includes an "add to cart" button. However, the actual cart is located outside the component in index.html, so ...

"Mastering the art of CSS: when the cascade goes

Can someone assist me with a tricky cascading style problem that is not so straightforward? I need to override a CSS child style with another style of equal importance (012), without changing its order in the CSS sheet... To see a concrete example, pleas ...

What is the best way to ensure that CSS links resolve properly when incorporating a PathInfo value?

Having an issue with my asp.net 3.5 app. Whenever I try to add a value to the URL for Request.PathInfo, it seems like I lose all connections in the head section because the paths are resolved as relative. This is how the master page appears: <head id= ...

Bootstrap 4: Adding a "Do not display again" option to a modal using a checkbox

I am struggling with getting my modal to disappear permanently when the checkbox "Don't show me again" is checked and the button "Close" is pressed. I have attempted using jquery-cookie, but so far I have been unsuccessful in achieving this desired be ...

Utilizing the Card-columns feature in Bootstrap

One issue I am currently facing is the way my generated cards appear in the card-columns div: while($row = $categorias->fetch_assoc()) { $imagen = $row["Imagen"]; $categoria = $row["Categoria"]; echo "<div class='card'>"; echo " ...

The flex order in my responsive layout with three columns is not being honored

I'm trying to create a three-column layout on my website using flexboxes. However, the 'commentCaMarche' div is not behaving as expected and is appearing at the top of the 'details-index' column. Any ideas on how to fix this issue ...

Navigating through nested <ul> elements using Selenium and C#

Currently, I am attempting to loop through the <li> items within a <ul> object using Selenium with C#. As a newcomer to this, I am exploring ways to simplify the coding process for my testing project. Below is a snippet of the HTML code that I ...

Basket removal with smooth sliding animation

I need help with adding a sliding animation to my application when removing an element by clicking the 'remove from basket' button. I have tried several methods but haven't been successful. Can anyone assist me in incorporating the animation ...

Enclosing text with border-wrapped image shadows

Before: After: Using the following pair of images: My HTML: <table class=full> <tr> <td class=showTemp2> THE CONTENT GOES HERE<br><br> SURROUNDED BY THE TWO SHADOW IMAGES<br><br> AND THAT'S IT </td> ...

CSS method for creating designs surrounding text

I'm working on styling a section of a website with a pattern running alongside certain pieces of text. I've included a screenshot taken from the PSD file to illustrate the issue I'm facing, with red arrows indicating the areas that are posin ...

The Ajax POST method may not be initialized, but it can still trigger a portion of a PHP if statement

Having trouble with Ajax when trying to send data from page1 to page2. Even though an if statement on page2 indicates that $_POST is not set, some of the code still runs, but not all. This issue is occurring on both XAMPP and my web-server. Here's th ...

Alignment of cells in a table

This problem is really bugging me. I've done my research and never had trouble with this before, but for some reason, I can't get the second div to display on the right side of the table cell. Any assistance would be greatly appreciated. Here is ...

Place a small image within a list item to ensure it matches the height of the list element

I need help aligning images to the right within list elements. The images are squares with equal height and width, and I want them to fit snugly within the height of the list element on the right side. My HTML code is quite simple for now (see example bel ...

Technique in CSS/SASS to repair a div

Seeking a solution for fixing divs with text in CSS. I am aware of the background-attachment: fixed; property which creates a fancy effect. Is there a similar property to "fix" divs with text or how can this be achieved in Typescript? Your insight would be ...

The logo emerges from the background color, with the text consistently appearing in black

In my attempt to display a logo and text together in an Outlook page, I encountered an issue. The content from the HTML page appears different when sent to MS Outlook. Despite not using flexbox in my HTML code, Outlook interprets it differently. I am uncer ...

What steps should I take to create a collapsible Bootstrap navbar?

I'm attempting to recreate the scrolling functionality seen here: It seems like they might be using a customized Bootstrap Navbar, so I've taken one from here: and tailored it to my needs. How can I achieve the effect where the navigation bar ...

Scrapy Library's Response.css function fails to retrieve data from API, resulting in an empty list

scrapy shell 'https://www.samsung.com/in/smartphones/galaxy-m/' fetch('https://searchapi.samsung.com/v6/front/b2c/product/finder/gpv2?type=01010000&siteCode=in&start=1&num=12&sort=onlineavailability&onlyFilterInfoYN=N& ...

as you lower a div element, the background image will also be shifted

While working on a rails project, I mastered all the rails elements easily. Surprisingly, I encountered an issue with CSS this time - something that is not usual for me as I usually face Ruby problems! The problem arises when trying to move a div element ...

Problem arises with table nth-child selector following the addition of grid-gap

Our current table looks like this: https://i.sstatic.net/eUyBB.png The first row has a background color and the second row is white - which is correct. Now I would like to align the attributes to the right. I added the following code to the table: .table ...

Creating the Required Input Attributes for a Contact Form

I am facing an issue with making all the inputs required in the contact form. I attempted to follow the logic used by w3schools, like <input type="text" id="username" name="username" required> However, my situation is d ...