What is the best way to eliminate the gap between two columns of square containers?

ref image

How can I create equal spacing between two columns of blocks?

Please help me with the following code:

        <div class="row">
            <div class="col-md-6">
                <img src="./img/02.jpg" class="img-fluid" alt="Image">
            </div>
            <div class="col-md-6">
                <div class="row">
                    <div class="col-md-6">
                        <div class="square-container bg-primary"></div>
                    </div>
                    <div class="col-md-6">
                        <div class="square-container bg-secondary"></div>
                    </div>
                    <div class="col-md-6">
                        <div class="square-container bg-success"></div>
                    </div>
                    <div class="col-md-6">
                        <div class="square-container bg-danger"></div>
                    </div>
                </div>
            </div>
        </div>

Here is the CSS that I am using:

body {
    font-family: 'Exo 2', sans-serif;
    width: 100%;
    height: 100%;
    background-size: cover;
}

p {
    font-family: Verdana, Geneva, Tahoma, sans-serif;
}

.square-container {
    width: 220px;
    height: 235px;
}

.grid-gap {
    display: grid;
    grid-gap: 1em;
}

I attempted to utilize grid for spacing but all the squares ended up in one column. Can you please advise on how to achieve equal spacing between the columns?

Answer №1

When using the bootstrap framework, the col-md-6 class is set to have a width of 50% with padding of 15px on the left and right.

To eliminate any extra space between columns, adjust the width of the .square-container to 100% so there is no excess space within the column itself.

If you require more or less space than the default 15px, you can manually override this setting or utilize gutters for spacing between columns.

For further information on bootstrap gutters, refer to the bootstrap gutters documentation.

View an example on jsfiddle.

Answer №2

Implementing css grid with display: grid allows for easy customization of columns and spacing using the gap property.

Answer №3

Utilizing the bootstrap row class means you can simply use the g class for creating gaps. Just follow this sample code snippet:

       <div class="row gx-4 gy-4">
            <div class="col-md-6">
                <img src="./img/02.jpg" class="img-fluid" alt="Image">
            </div>
            <div class="col-md-6">
                <div class="row">
                    <div class="col-md-6">
                        <div class="square-container bg-primary"></div>
                    </div>
                    <div class="col-md-6">
                        <div class="square-container bg-secondary"></div>
                    </div>
                    <div class="col-md-6">
                        <div class="square-container bg-success"></div>
                    </div>
                    <div class="col-md-6">
                        <div class="square-container bg-danger"></div>
                    </div>
                </div>
            </div>
        </div>

To add spacing, I have utilized gx for horizontal spacing and gy for vertical spacing. If desired, you can simply use g for both horizontal and vertical spacing.

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

Doesn't IE support the use of jQuery.last()?

Here is the code snippet I am currently using: $('script').last().parent().html('kkkk') Unfortunately, I am encountering an error in Internet Explorer when running this code. Any suggestions on how to address this issue would be great ...

Using TypeScript, apply an event to every element within an array of elements through iteration

I have written the code snippet below, however I am encountering an issue where every element alerts the index of the last iteration. For instance, if there are 24 items in the elements array, each element will alert "Changed row 23" on change. I underst ...

Proper method for verifying line-clamp in a Vue component

I came across a question that aligns perfectly with my current task - determining if text is truncated or not. The query can be found here: How can I check whether line-clamp is enabled?. It seems like my approach may not be accurate, so any guidance on ho ...

I am unable to load any HTML files in my VueJS iframe, except for the index.html located in the public

Within the template of my vue component, I am utilizing the following code: <iframe width="1000vw" height="600vh" src="../../public/myHtmlFile.html"></iframe> Unfortunately, the file specified in the src attribut ...

Adding a click function to a div individually when they share the same class in HTML

My goal is to include 4 unique divs inside a timeline container: This is how I envision the structure: <div id="timeline" > <div class="timeline-bar t-1"></div> <div class="timeline-bar t-2"> ...

Adjusting the empty image source in Vue.js that was generated dynamically

Currently experimenting with Vue.js and integrating a 3rd party API. Successfully fetched the JSON data and displayed it on my html, but encountering issues with missing images. As some images are absent from the JSON file, I've saved them locally on ...

Implementing AngularJS drag and drop functionality in a custom directive

I am in search of an example that demonstrates similar functionality to the HTML5 File API using Angular-js. While researching directives for Angular 1.0.4, I found outdated examples that heavily rely on DOM manipulation. Here is a snippet of the pure Ja ...

Navigating around web pages with Python and Selenium: How to interact with non-button elements through clicking

I am currently working with Python's selenium library and trying to interact with an element that is not of the button class. My browser/web driver setup involves Google Chrome. Below is my code snippet for reference: from selenium import webdriver ...

What is the best way to eliminate leading zeros in PHP when echoing SQL statements?

Being a front-end programmer on a team of three, my PHP/MySQL skills are fairly basic. However, our back-end programmer is going on vacation and we have a deadline to address a minor visual detail. Currently, we are working on a page that displays multiple ...

Issue encountered when integrating AJAX with PHP and HTML5 form

I've been working on solving a puzzle involving a contact form that uses AJAX and PHP. I decided to try reverse engineering the PHP code from this page (). However, when testing it out, the message gets stuck at "sending message...." after clicking "S ...

What is the process for making a local storage item accessible to others on a network?

Can a local storage item be accessed from any computer on the network using the same Google Chrome extension that was previously set up? ...

Is it possible to execute an Ajax Request using JQuery?

I've been attempting to update the content within a <div> using a JQuery Ajax Call, but unfortunately I'm encountering some difficulties. Whenever I click on the onclick <a> element, nothing seems to happen. Below is the code that I a ...

Creating overlapping layouts with absolute positioning in Bootstrap leads to a visually appealing

I'm currently working on a layout that involves absolute positioning elements, similar to the one shown in this example: https://i.sstatic.net/TixbZ.jpg It seems like the elements are overlapping and not clearing properly. I've been looking for ...

Click on the link within the Checkbox label on MUI

I am working on creating a checkbox for the "Terms of Use," using FormControlLabel to nest a Checkbox. However, I also need to include a link that opens a Dialog component displaying the terms. The challenge is that clicking on the link checks the checkbox ...

jQuery carousel displaying a blank slide at the conclusion

I am experiencing an issue with my slideshow where it shows an empty slide after the last element. I suspect that there is something in my script causing this behavior, as it seems to be finding one extra child for the element and adding it as an empty spa ...

Displaying content conditionally - reveal a div based on user selection

I have a dropdown menu and need to determine whether to display a specific div using the value selected via v-if. <select class="custom-select custom-select-sm" id="lang"> <option value="1">English</option> <option value="2">Sv ...

The Font Awesome icons do not display offline

I'm having trouble using Font Awesome icons offline on my webpage. I've included the necessary code, but for some reason it's not working. Here is what I have: <html> <head> <title>font-awesome example</title> ...

Is it possible to create a WebXR using the ARCore API specifically for IOS devices?

I'm experiencing an issue with my code that seems to be working flawlessly on Android devices, but when attempting to run it on an iOS device, clicking the button to start the AR session yields no results. I reached out to ChatGPT for assistance, and ...

Animation will begin once the page has finished loading

On the website, there is a master page along with several content pages. The desired effect is to have a fade-in animation when navigating between pages. Currently, when clicking on a link, the new page appears first and then starts fading out, but this sh ...

What is the method for incorporating a CSRF token into BootstrapTable when using the POST data method?

How can I include a CSRF token in bootstrapTable when using the POST method for data? I am working on a project and trying to add a CSRF token in bootstrapTable. There is some information about CSRF on bootstrap-table.com. Can anyone help me with this iss ...