Ways to create spacing between grids in Bootstrap 4

Adjacent to one another are 3 divs styled with classes as follows:

<div class="col-sm-12 col-md-4"></div>

Is there a way for me to include margins on the left and right sides of these divs? When I try to add them manually - such as margin-left or right 15px - it disrupts the layout and the divs no longer appear side by side.

Answer №1

As mentioned previously:

Consider using col-md instead of col-md-4

Utilize mx-md-x to add or remove margins. For more information, refer to the Bootstrap 4 resources: https://getbootstrap.com/docs/4.5/layout/grid/ & https://getbootstrap.com/docs/4.5/utilities/spacing/

Demonstration:

.row>div {
  border: solid;
}

.bg-warning>div:after {
  content: ', no margins available';
}

.col-md:after {
  content: ', margin available.';
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
  <div class="row bg-warning text-dark">
    <div class="col-sm-12 col-md-4">1</div>
    <div class="col-sm-12 col-md-4">2</div>
    <div class="col-sm-12 col-md-4">3</div>
  </div>
</div>
<hr>
<div class="container">
  <div class="row">
    <div class="col-sm-12 col-md bg-success text-warning">1</div>
    <div class="col-sm-12 col-md mx-md-2 bg-success text-warning">2</div>
    <div class="col-sm-12 col-md bg-success text-warning">3</div>
  </div>
</div>

https://i.sstatic.net/MYWsj.jpg

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

What is the best way to design a responsive menu that is perfectly centered?

I'm facing challenges with designing a menu that includes 4 items, needs to be centered next to each other with spacing in between, and should stack vertically on mobile devices. The desired look for the menu can be viewed in this image... https://i. ...

Struggling to alter Material-UI theme styles

I have been working on a project using Material-UI and I am trying to change the default theme style of textTransform:"uppercase" to textTransform:"capitalize." After checking out the documentation on custom styling, I learned that I should use inline sty ...

Custom stylesheet for individual users?

On my website, users can pick a template for their webpage. After selecting a template, I would like them to have the ability to customize certain styles like the font color. Is there a way to achieve this? I was thinking about saving the user's cus ...

Can an element be positioned in relation to the border-box of its parent element?

Check out this jsfiddle for an example: http://jsfiddle.net/apmmw2ma/ <div class='outer'> <div class='inner'> Inner. </div> Outer. </div> div.outer { position: absolute; left: 10px ...

Div displaying white blank space due to Internet Explorer 11 issue

While working on creating a print-friendly version of a webpage, I encountered a puzzling issue with Internet Explorer 11. Both the webpage itself and the print preview are showing some unexplained blank space below the div elements. I have meticulously c ...

Resources for Learning HTML5, CSS3, and JavaScript

Currently on the hunt for comprehensive resources that delve deep into HTML elements like <audio>, <video>, and <canvas>. I want to explore how JS and CSS/CSS3 can be leveraged to craft interactive graphs/games and illustrations using the ...

Basic code with an onclick function runs smoothly on Chrome, but encounters issues on Firefox

Struggling with a peculiar issue while trying to create a userscript using jQuery and JavaScript. The problem arises when attempting to add an onclick event to an image. Surprisingly, it works perfectly in Chrome (with TamperMonkey), but fails to respond i ...

Transfer the textbox value from page-1 to page-2 seamlessly with the help of AngularJS UI-routing

I'm attempting to transfer the textbox value from Page-1 to Page-2 using the code below, but I am encountering difficulties. Page-1.html <div > <div style="height: 400px"> <h2>Partial view-1</h2> <p> ...

Using HTML5 chunks and web workers will not involve any uploading of files

I encountered an issue while working with html5 slice and webworker. It seems that when I try to upload a file using the uploadFile function, nothing is happening and the file is not being uploaded. <html> <head> <title>Uploa ...

PHP function ending with a 0

This tutorial was initially sourced from W3Schools, but I have made some changes to the PHP file to integrate Wordpress hooks and adjusted the JavaScript file to accept two variables. This modification enables the code to be utilized multiple times within ...

Font and div placement varies on a mac within a WordPress environment

www.oihanevalbuenaredondo.be After styling my post titles in CSS using font-family: adobe arabic, I noticed that while they display correctly on my Windows machine, they appear in a basic font on Mac OS, Safari specifically. Why is it that Safari cannot r ...

Understanding AngularJS and how to effectively pass parameters is essential for developers looking

Can anyone help me figure out how to properly pass the html element through my function while using AngularJS? It seems like this method works without AngularJS, but I'm having trouble with the "this" keyword getting confused. Does anyone know how I c ...

Adding the Bootstrap4 CDN seems to break the animations on my website

<div class="mySlides fade"> <img src="https://media.giphy.com/media/9JpsWBPgRtBDOYE6QB/source.gif" style="width:100%; height: 100%; border-radius: 0; "> </div> <div class="mySlides fade"> ...

Optimal method for relocating an element efficiently

I'm currently working on a project where I need to implement horizontal movement for a DOM element. The movement should start on mousedown, continue on mousemove, and end on mouseup. This task is especially challenging due to the site's numerous ...

Tips on preserving dynamically generated table upon window refresh

Here is my code snippet that creates a dynamic table when a button is clicked: -Createlist() function is triggered when the "create table" button is clicked, adding a new table row each time. -Deletelist() function is called when the "remove table" butto ...

Delete the initial image from the opening list item using jQuery

Here is an example of some HTML code: <ul class="products"> <li> <a href="#" class="product-images"> <span class="featured-image"> <img src="img1.jpg"/> <img src="img ...

Is it possible to view the CSS of a PDF file in print template mode using Chrome?

https://i.stack.imgur.com/XlcWm.png Currently facing an issue with debugging CSS on my PDF template. I am unable to inspect the styles directly in the CSS due to limitations. When using inspect element in Chrome, only the styles for text and elements are ...

Is there a way to transform text input into a dropdown menu that dynamically alters the rows of a table?

Currently, I am working on creating a drop-down menu selection that will dynamically change the table rows based on user input. At the moment, users can enter their input into a text field to see changes in the table rows. However, I would like to impleme ...

Navigate to the specified text in the dropdown menu based on the ul li selection

Is it possible to achieve a functionality similar to that of a select box, where typing a keyword that matches an option in the select box will automatically move the pointer to that option? I am looking to implement a similar feature in my HTML code: < ...

Tips on positioning a button "above" the carousel-control-next icon

I have a carousel and I added a button to stop the spinning. However, when I try to click on the button, it seems like the "carousel-control-next" tag is being clicked instead. How can I solve this issue? ** Interestingly, when I remove the "carousel-cont ...