How to properly adjust Margin and Padding in Bootstrap using Container and Columns

After spending hours using Bootstrap 4.1, I am struggling to align columns within a container. The margins and paddings are not cooperating:

My goal is to create a 2x3 grid on large screens with items boxed and framed around them. However, there seems to be a significant gap (perhaps 30px) between the two columns with the current code. How can I remove this space? Editing padding and margins has not been successful.

Here is the code snippet in question:

.test-container{
  border: solid red 1px;
  padding: 1px;
  margin:auto;
}

.item{
  border: solid 1px black;
  height: 70px;
  margin: 1px;
}

.row{
  padding: 0px;
}
<div class="container-fluid border-top bg-white shadow">
        <div class="col-sm-9 test-container">
            <div class="row">
                <div class="col-md-6">
                    <div class="item">Select Unit</div>
                </div>
                <div class="col-md-6">
                    <div class="item">Unit 1 / Unit 2</div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-6">
                    <div class="item">Input:</div>
                </div>
                <div class="col-md-6">
                    <div class="item">Value_Input</div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-6">
                    <div class="item">Output</div>
                </div>
                <div class="col-md-6">
                    <div class="item">The result is...</div>
                </div>
            </div>
        </div>
    </div>

I am seeking a simple solution but I seem to be stuck. Any help would be greatly appreciated.

* EDIT * Upon review, it appears that the code generates a 1x6 column layout. While this is suitable for small screens, on larger screens I desire a gapless 2x3 grid layout.

Answer №1

Your HTML looks good. By default, Bootstrap columns have padding of 15px on the left and right, while rows have -15px to counter this at the edges. To achieve your desired layout, you can use the following CSS:

.row{
  padding: 0 15px;
}

.col-md-6 {
  padding: 0;
}

This CSS code removes padding from columns to eliminate gaps between them and adds 15px padding to each row to fit the columns into your designated container.

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

A guide to sending HTML emails with the Linux command line

I am in search of a solution to send emails in HTML format using only the Linux command line and the "mail" command. So far, I have tried the following: echo "To: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="99f8fdfdebfceae ...

React.js combined with Webpack may not properly interpret @media queries

Currently, I am working on a website built with React.js (version 15.6.1) and Webpack 1. I have implemented a SASS-compatible version of the Flexbox Grid following this tutorial. However, I have noticed that the @media expressions are not being compiled as ...

Implementing a three-column layout with images using Bootstrap

I am currently utilizing a Bootstrap layout that features two columns. However, I am now looking to include a small image to the right of an input field. This image needs to be displayed next to the input field snippet. Here is the HTML structure I am wor ...

Learn the art of perfectly aligning text in bootstrap 5

I am looking to align text in the same way shown in this image from Libre Office. Libra Office: https://i.sstatic.net/1dvVx.png This is how the webpage appears: https://i.sstatic.net/JnFSP.png Is there a way to make the webpage resemble the formatting i ...

Setting a conditional class based on the iteration value of a loop within a v-for statement

When generating table rows using the v-for"x in y" directive, I also want to apply certain classes conditionally based on a value within the loop. For example: <tr v-for="file in fileList" :class="{ 'bg-green': file.include }"> <td&g ...

Icon with label and border using Font Awesome

I'm looking to recreate this design using HTML and CSS: https://i.sstatic.net/LUgGW.png The icon I'm trying to replicate is actually from font awesome. Here's what I've accomplished so far: https://jsfiddle.net/0Lewug6p/1/ &l ...

Align text vertically above and below an input field labeled using tailwindcss

I am striving to achieve the desired outcome but with the text in front of the input vertically aligned with the text after the input. https://i.sstatic.net/0WTfk.png Here is what I have created so far to accomplish that: <div class="space-x-2 fl ...

JavaScript Mobile Redirect HTML

Despite numerous attempts, I have been unable to get the mobiledetector script to function as desired for my mobile viewers. My goal is to include a link on the mobile site that allows users to access the full site without being redirected back to the mobi ...

The memory usage steadily increases when you refresh data using the anychart gantt chart

I have a basic anychart code to update a gantt chart every second: function initializeSchedule(){ anychart.onDocumentReady(function () { anychart.data.loadJsonFile("../scheduler?type=getschedule", function (data) { documen ...

Download personalized HTML design

Situation When exporting to HTML, the resulting code appears as follows: <html> <head> <title></title> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> <style type="text/css" ...

Using Previous and Next Buttons in Bootstrap Tabs for Form Navigation

I am currently facing a challenge in splitting a form into multiple tabs and encountering issues with the next and previous buttons on the second and third tabs. My goal is for the tabs at the top to change state as you cycle through them by clicking the ...

All hyperlinks are displayed as a single entity

I have 5 image links displayed side by side, but when I hover over them, they act as one collective link. Can someone please assist me with resolving this issue? After updating my code to include the entire div, it seems that there is something within the ...

Showing an array of detailed high-quality images on an HTML canvas with map tiling

My project involves using three.js to showcase a globe. Initially, the image quality is low, but as the user zooms in, the images become clearer and higher in quality. This is achieved through the use of tiling. Each tile measures 256px x 256px. For the lo ...

navigating through tab menus based on time intervals

I'm a beginner in the world of HTML and website building. I have all my content ready to display on my site, but I'm looking for assistance in automating tab switching. Is it feasible to alternate between tabs every 5 minutes? Can someone guide m ...

Can you show me how to magnify multiple images when hovering over them without altering their dimensions?

I am working on a gallery that features multiple images and I want the images to zoom in when hovered over without resizing the container. My project is built using Bootstrap 4. <div class="row"> <div class="col-12"><img ...

What information is transferred when the submit button on a form is clicked?

Currently, I am utilizing node.js along with the jade templating engine. Within my jade file, I have a form structured like this: form.form-signin(style="padding-left:10px", action='/update', method='post') table.table.table-hove ...

Achieve vertical center alignment of text without using line height or table cells

Looking to add a "toggle" animation on my Teaser, here's the code: .ax { height:60px; width:150px; background:gold; } .caption { position: absolute; left:0; top: 35%; overflow: hidden; right: 0; background-colo ...

Utilizing AngularJS in conjunction with Asp: UpdatePanel

<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminMasterpage.master" AutoEventWireup="true" CodeBehind="ExamSet.aspx.cs" Inherits="demo.Admin.ExamSet" %> <asp:Content ID="Content1" ContentPlaceHolderID="content" runat="server"> <s ...

Expandable rows within an Angular Material table (mat-table) feature a distinct gap, even when rows are collapsed

I recently integrated an Angular Material table into my website, following the examples provided on the official Angular page (link to the examples). I wanted the table rows to be expandable similar to the "Table with expandable rows" example on the Angula ...

Transfer data in an array within value="" separated by ':' through AJAX/JSON in PHP and HTML

Can data be passed in array form using AJAX/JSON? For example, like ".$row['departmentname'].":".$row['jobposition'].":".$row['deptcode']."? Here is a sample code snippet to illustrate this: if(sqlsrv_num_rows($query) > 0 ...