Bootstrap 4 does not have the capability to include spacing between two columns

I'm encountering an issue with adding a gutter between 2 columns on my website layout. I have a row that needs to be 1280px wide (based on a reference resolution of 1366x768 with padding of 43px on each side of the page), containing two sections that should be 620px wide each with a 40px gutter in between. The problem is that the columns end up being half of the view (640px), leaving no space for the gutter (even though I assumed it would be automatic). The default gutter has already been set to 20px on each side.

<div class="wrapper">
  <div class="row">
    <div class="col-lg-6 row a">
      aaa
    </div>
    <div class="col-lg-6 row b">
      aaa
    </div>
  </div>
</div>
.wrapper {
  padding: 0 43px;
  background: red;
  height: 100vh;
}

.a {
  background: blue;
  margin: 0;
}

.b {
  margin: 0;
  background: green;
}

Answer №1

One important thing to note is that it is not recommended to use the row class along with the col-**-* class.

Another key point is that when you use your custom class with the col-**-* class and apply a background-color, it will cover the entire area of your column. To avoid this, make sure to place your custom class as a child element of the col-**-* class and then apply the background-color to your custom class.

Here is the snippet displayed in full-width:

.container {
  padding: 0 30px;
  background: red;
}

.custom-class1 {
  background: blue;
  margin: 0;
}

.custom-class2 {
  margin: 0;
  background: green;
}
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Example</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" />
  <link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
  <div class="container">
    <div class="row">
      <div class="col-lg-6">
        <div class="custom-class1">Content 1</div>
      </div>
      <div class="col-lg-6">
        <div class="custom-class2">Content 2</div>
      </div>
    </div>
  </div>
</body>
</html>

Answer №2

include a container inside your wrapper

<div class="wrapper">
 <div class="container"> <!-- or container-fluid -->
  <div class="row">
    <div class="col-lg-6 row a">
      aaa
    </div>
    <div class="col-lg-6 row b">
      aaa
    </div>
  </div>
 </div>
</div>

explore the functionality of .container and .container-fluid classes here: https://getbootstrap.com/docs/4.3/layout/overview/

Answer №3

From my understanding, adding gutters is a simple task that doesn't require writing CSS code. Bootstrap actually provides this feature automatically. You can achieve this by simply adding "no-gutters" to the div class like

<div class="row no-gutters">

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

Ways to create a separator or divider between rows in a table

I'm currently working on creating a table layout and I want to include dividers similar to those seen on this website. Specifically, I am looking to have thin grey dividers between rows. I've attempted the following code, but it doesn't seem ...

Ways to make a div non-clickable disappear without using JavaScript - A guide on "lightboxing" a div

I would like the score's div to pop up as a lightbox when clicking on this link : <a href="#test">TEST</a> However, I do not want it to disappear when clicking on the div itself, only on the black background! Here are my attempts: < ...

Creating a toggle button for a div element to expand and collapse its content: Step-by-step guide

For my e-commerce site selling musical instruments, I'm designing a product landing page that showcases guitars, keyboards, violins, and cellos. As part of the design, I want to include expandable sections with detailed information about each instrume ...

HTML - Customizing container with background color and ensuring minimum height of 100%

After creating a dynamic page using Bootstrap, I managed to add a sticky nav bar and footer. The navbar, footer, and page content are all in black color. I want the main content area to be white with black sides matching the background. Currently, I ca ...

How can I adjust height without affecting weight in CSS using curly brackets?

Can CSS be used to specifically adjust the height of a curly bracket without changing its thickness? I have been attempting to modify the height of a curly bracket dynamically by adjusting the font-size, but this also alters the weight. Is there a workar ...

The javascript code appears to be functioning properly on desktop browsers but is not functioning as expected on Chrome's mobile browser

On my WordPress site, I have created a Java Bootstrap loan calculator that works perfectly on desktop. However, when I use Chrome on mobile, it is not functioning properly. I tried using the wp-coder plugin and also manually added the necessary code. Int ...

Are you looking for methods to alter the elements of a webpage prior to viewing it?

I have created a page with the intention of using it as a tool, but I am facing some challenges due to my limited experience in this field. As a newcomer, I am struggling to achieve certain goals: - My objective is to modify the values of an element on a p ...

Switch between showing and hiding a div by clicking on the panel header and changing the symbol from + to

I need assistance with a panel feature on my website. The panel should expand when the "+" symbol is clicked, displaying the panel body, and the "+" symbol should change to "-" indicating it can be collapsed by clicking it again. There is a slight twist t ...

Aligning elements in the middle of a div, from side to side

If you imagine a container div that is 100px wide, and inside it there are 3 smaller divs each 20px wide. I am wondering how to align these smaller divs so that they are centered within the container div, with a 20px gap on each side? ...

Issues arise: Bootstrap unexpectedly fails in my React JS project

Unexpectedly, bootstrap has ceased to function on my current project. The reason behind this sudden issue is unknown to me at the moment. Below is a snippet from our package.json file: { "name": "blankets", "version": "0.1.0", "private": true, ...

Loading Animation for Pages and Tables

I'm experiencing a choppy and sudden transition when switching between two pages that contain tables populated using ng-repeat. Upon loading, the footer is positioned halfway up the page below the table heading until the table loads and the layout adj ...

Shift the element within the div towards the left side

I am trying to create an animation for an element that moves to the left when hovered over, but the code I thought was correct doesn't seem to be working in my fiddle. Here is the link to the fiddle I created: https://jsfiddle.net/feb8rdwp/3/ Based ...

Turn off images using Selenium Python

In order to speed up the process, I believe that disabling images, CSS, and JavaScript can help since Webdriver waits for the entire page to load before moving on. from selenium import webdriver from selenium.webdriver.firefox.firefox_profile import Firef ...

Guide to inserting an HTML file into an article's content

After downloading an extension from freefrontedit and uploading it to my server in the directory /accordeon, I successfully accessed it by pointing my browser to . However, I am now faced with the challenge of loading the index.html into my Joomla article ...

Guide to repositioning elements and fixing the functionality of the hamburger button: [ HTML & Bootstrap ]

Looking for help with creating a navbar for a website using HTML and Bootstrap. Need to move the header and link to the ends of the navbar and ensure that the hamburger button displays correctly on different screen sizes. Here's how it looks on deskt ...

The el-dialog is functioning properly, however, I am looking to add CSS that will animate it to open

I've set up a dialog to open on button click, and it's functioning correctly. My goal is to have the dialog open from the bottom with a height of 300px, show the contents inside it, and then hide when I click outside or inside any element. Here ...

What could be the reason behind the improper display of JavaScript for ID overlay2?

Why is it that when I try to have two overlays with different messages display upon clicking buttons, they both end up showing the same message? Even after changing the ID tag names, the issue persists. Can someone shed some light on what might be causin ...

Styling the select dropdown border in Google Chrome

I am encountering an issue with styling HTML select options in Chrome. Despite successfully applying borders to each option in Firefox, I cannot get it to work in Chrome. Can anyone advise on how this can be achieved? <select id="sortingOptions" class= ...

The Joys of Delayed Animation with jQuery Isotope

Has anyone successfully modified the CSS3 transitions in jquery Isotope to incorporate a delay for shuffling items, such as using "transition-delay: 0s, 1s;"? I am aiming for a specific shuffle direction - first left, then down - to create a more calculat ...

Ensuring continuous execution of JS EventListener

The other day, I received a solution from someone on this platform for a script that changes the color of a div when scrolling. Here is the code I implemented: const x = document.getElementById("menuID"); window.addEventListener("scroll", () => { ...