Tips for maintaining the even spacing of three responsive divs without using flexbox

Whenever I try to add margins between the three columns in the third <div>, it breaks into a new line and disrupts the layout. I've experimented with adding margins, adjusting the value using percentages, and even tried implementing box-sizing: border-box, but nothing seems to work.

This is the current outcome:

Large Screens:

Medium Screens:

This is what I was hoping for:

Large Screens:

Medium Screens:

/*For responsive layout*/
.container{
    padding-left: 20px;
    padding-right: 20px;

    
}
.row{
    width: 100%;
    
}

/**For Large Devices**/
@media (min-width: 992px) {
   
    .col-lg-4{
        float: left;
        width: 33.33%;
    }
}

    

/*for medium devices*/

@media(min-width:768px) and (max-width:  991px){
    
    .col-md-6, .col-md-12{
        float: left;

    
    }
    
    .col-md-6{
        width: 50%;
    }

    .col-md-12{
        width: 100%;
    }

}

*{
    box-sizing: border-box;
    margin: 0px;
    padding: 0px;
    font-family: Arial, Helvetica, sans-serif;
 
}


h1{
    text-align: center;
    margin: 2%;
   
}

div .title{
    float: right;
    margin-top: 0px;
    margin-right: 0px;
    text-align: center;
    padding-left: 5%;
    padding-right: 5%;
    background-color: rgb(255, 123, 0);
    border: 1px solid black;
    font-size: x-large;

}
#beef{
    color: aliceblue;
}

.section{


    background-color: grey;
    margin-top: 20px;
    border: 1px solid black;
 
    
    
}

p{
    padding: 10px;
    clear: right;
    text-align: left;
    margin: 2%;
}


I'm stuck and seeking assistance. Please help!

Answer №1

To create evenly spaced divs that respond well to different screen sizes without relying on flexbox, CSS Grid can be a powerful tool. Check out this code snippet for implementing this approach:

  margin-left: 15px;
  margin-right: 15px;
}

.row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-column-gap: 15px; /* Adjust the gap based on your design */
}

.col-lg-3 {
  /* Ensure no changes are necessary for larger screens */
}

/*

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

Dynamic HTML Table with Ajax Click Event Trigger

I have implemented an HTML table that refreshes automatically every 5 seconds and contains some buttons. The issue I am facing is that the event only triggers before the initial refresh. <?php require_once ('UserTableHtm ...

Using JQuery to dynamically change className based on specific logic conditions

I am struggling to dynamically change the class name of a div based on the text inside another div using jQuery. Here is an example of the HTML structure: <div class="div-overlay"> <a class="image" href="https://www.e ...

"Going beyond the ordinary: An exclusive look at the Outlook newsletter design

I'm struggling with adding text and a background image to a TD in a newsletter. While the background shows up, the text is not being displayed as expected. Below is the code snippet I've been using: {if !empty($aModules.mkNews)} ...

Seamless flow from one image to the next

I'm working on a project with a slideshow, but I've noticed that when it transitions between images, it can be quite abrupt. I'd like to find a way for it to change smoothly from one image to the next. <div> <img class="mySli ...

Smoothly transition the background hue of the moving <h2> element

Check out this plunker demonstrating the issue This plnkr showcases a login interface with a sliding div that appears when clicked. Clicking on 'Down' will smoothly transition it back down. The issue lies in my <h2> tag, which also change ...

Disable top margin for <body> on smaller screens using Bootstrap 4

I'm facing a dilemma about my webpage created with Bootstrap 4. Despite numerous adjustments, all the elements on the page are displaying correctly. However, on smaller screens, it seems like there is an unexpected top-margin within the <body> t ...

Searching for specific text within HTML href tags involves parsing the HTML document and

[I'm having trouble isolating links that contain the specific text '/Archive.aspx?ADID='. Even though I have tried to filter for these specific links, I end up retrieving all of the links from the webpage. Once I am able to extract the desir ...

Simple method to restrict duration of video uploads using HTML5's capture attribute

I'm working on a website that allows users to take photos and videos with their smartphones. Everything is running smoothly with HTML5 and some javascript, but I want to set a maximum time limit for the videos without requiring users to start recordin ...

`Angular 9 template directives`

I am facing an issue with my Angular template that includes a ng-template. I have attempted to insert an embedded view using ngTemplateOutlet, but I keep encountering the following error: core.js:4061 ERROR Error: ExpressionChangedAfterItHasBeenCheckedEr ...

Using jquery to dynamically set the value of a drop down menu

I am struggling with a dropdown list that is being generated dynamically using ajax when the page loads. Additionally, I have a PHP variable that holds the default selected value. However, despite my attempts to select this value, it does not work as expec ...

How can I programmatically control the scrollbar of an iframe displaying a PDF using JavaScript?

As I explore ways to display PDF documents on a Smart TV, I have decided to implement invisible buttons for scrolling up and down the document. This functionality needs to be integrated into a web environment, so this is what I have attempted: Here is the ...

What methods are available for collecting a list of identifiers from a webpage?

I am facing a challenge while scraping a web page using Selenium. Here is the code snippet I am working with: <h4 class="category" id="sc_14295">...</h4> <h4 class="category" id="sc_14292">...< ...

Grid items displaying incorrectly due to text alignment issues

I'm facing an issue where I need to separate text and the money part, and also align the text in a way that when viewed in smaller text sizes, the money part moves to the next line. .outdoor-card { display:flex; flex-wrap: wrap; width: 100%; ...

The art of expertly placing the arrow in <details> with CSS

I'm looking to adjust the placement of the arrow within details. I've experimented with using float:left, but when the line is too long, like in the example provided, the arrow shifts to the beginning of the line below when I resize the window. I ...

Is it possible to modify the shrinking behavior of Flexbox?

My goal is to mimic the layout of a specific webpage using flexbox in my version. However, I've noticed that my version, utilizing flexbox, adjusts to smaller screen sizes differently than the original. The original layout I'm trying to replicate ...

Combination of Bootstrap 4 Container and Fluid Container in Row with Column

I am attempting to design a layout that resembles the component displayed in the image. The layout consists of a 12 column Bootstrap grid. I would like the text to occupy 6 columns, with a spacer of 1 column between the text and the last column. The final ...

Interactive Timeline - Adjust color on click

I am having trouble implementing a timeline and changing the color when clicking on different states. Can anyone help me figure out what the issue is or how I can achieve this? I intended to give each state a different color, but sadly, it didn't wor ...

The CSS code for adjusting width, text alignment, and margin for the <a> tag is not functioning correctly

Currently, I am only able to get color, padding, and font codes to work in my HTML. When I attempt to add width or align the text to the right, it does not seem to work. <a href="https://www.football.london/chelsea-fc/transfer-news/juventus-chelsea ...

When I try to alter HTML using JS, I encounter an undefined error related to AngularJS

Using this specific function: function adjustContent(elemento){ if (document.getElementById(elemento).innerHTML.indexOf('&#10004;')>0){ document.getElementById(elemento).innerHTML=document.getElementById(eleme ...

Theming for Atom and Electron developer tools

After switching from the netbeans IDE to github's atom, I realized that some necessary features were missing. Unable to find a suitable package, I decided to try customizing it myself, gaining valuable insight into the editor in the process. However, ...