Issues with CSS not properly clearing div elements on mobile or responsive designs

We are currently facing an issue with the responsive divs in our project. Instead of clearing other div elements on the page, they are overlapping. Our project is built using bootstrap 4.3.1 and we would appreciate any assistance.

Feel free to visit this webpage to see the problem firsthand.

If you have any insights or solutions, please share them with us!

/* Code for creating two equal columns that float next to each other */

.column_left {
  float: left;
  width: 50%;
  padding: 10px;
  height: 250px;
  margin-bottom: 5px;
  border-radius: 10px;
  background: #E6E6E8;
}

.column_right {
  float: right;
  width: 50%;
  padding: 5px;
  height: 250px;
  margin-bottom: 5px;
  border-radius: 10px;
  background: #E6E6E8;
}

.setADS {
  float: right;
  margin: 0px;
}


/* Clear floats after the columns */

.setADS:after {
  content: "";
  display: table;
  clear: both;
}


/* Responsive layout - makes the two columns stack on top of each other instead of next to each other */

@media screen and (max-width: 600px) {
  .column_left,
  .column_right {
    width: 100%;
    bottom: 0;
  }
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a8cac7c7dcdbdcdac9d8e89c86cadad2dadffbcfc9d7dbd29bd1ded0">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">

<div class="setADS">
  <div class="column_left" style="background-color:#aaa;">
    <h2>Column 1</h2>
    <p>Some text..</p>
  </div>
  <div class="column_right" style="background-color:#bbb;">
    <h2>Column 2</h2>
    <p>Some text..</p>
  </div>
  <div class="column_left" style="background-color:#aaa;">
    <h2>Column 3</h2>
    <p>Some text..</p>
  </div>
  <div class="column_right" style="background-color:#bbb;">
    <h2>Column 4</h2>
    <p>Some text..</p>
  </div>
</div>

Answer №1

Your page structure needs some adjustments to address the current issues you are facing, as fixing one problem may lead to others in the future. Here is a basic structure that you can use to organize your code blocks:

When styling columns like column1, column2, etc., refrain from using custom styles. Instead, eliminate spacing between the blocks/columns by utilizing the predefined Bootstrap class 'no-gutter' within the row class.

Place the following structure after your header:

<div class="container-fluid">
  <div class="row">
    <div class="col-md-7">
      ... insert your content here.
    </div>
    <div class="col-md-5">
      <!-- Solution for divs column1, column2... goes below -->
    <div class="row no-gutter">
      <div class="col-md-6">column 1</div>
      <div class="col-md-6">column 2</div>
    </div>
    <div class="row no-gutter">
      <div class="col-md-6">column 3</div>
      <div class="col-md-6">column 4</div>
    </div>
    </div>
  </div>
</div>

Answer №2

Consider assigning a shared class name to all the elements you wish to group together, and apply flex:50%

.item {
  width: 100%
}

.root {
  display: flex;
  flex-wrap: wrap;
}

.root > div {
  flex: 50%; /* or - flex: 0 50% - or - flex-basis: 50% - */
  box-shadow: 0 0 0 1px black;
  margin-bottom: 10px;
}
<div class="root">
  <div class="item">Content A</div>
  <div class="item">Content B</div>
  <div class="item">Content C</div>
  <div class="item">Content D</div>
</div>

This is one way of achieving the desired layout

Answer №3

Your request seems a bit unclear, but by adding the CSS rule overflow: auto; to the #public-listings element, it will ensure that all floated child elements are contained within it, allowing the following element to appear below it and avoiding any overlapping issues.

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

Having trouble applying overlays to list items with CSS

I'm currently working on a grid gallery where I've set the List items to be 20% wide so there can be 5 in one row using float:left. Now, I'm trying to add an overlay effect by using a div with the class "overlay" so that when someone hovers ...

Using CSS to repeat a background image horizontally starting from a specified position

I am currently working on styling an h2 element with a 2px background image. My goal is to have the image start right after the text in the h2 and repeat horizontally for the rest of the space within the h2. However, due to varying word lengths, I cannot s ...

Create a mobile-friendly version of the website that retains all the functionality and features of the desktop

Currently, I am in the process of optimizing my website for mobile devices. However, creating a separate subdomain and folder for a new mobile version is proving to be a challenge since it was not originally requested. How can I ensure that the website ap ...

JQuery retrieves the text content without taking into account the class

I'm struggling with my code and encountering an issue fetching text while excluding the menu-list-count class which displays a value next to the text. Here's what I've attempted: var mailfolder = $(this).not('[class="menu-list-cou ...

Retrieve the current font style with Kendo UI Editor

Recently, I've been facing some challenges while working with the Kendo UI Editor. Specifically, I'm struggling to retrieve the current font style. My goal is to use JavaScript or jQuery to obtain the following values: Values I am looking for: ...

Tips for preventing scrollbar overlap

I am experiencing an issue with two scrollbars in my HTML file. Scrollbar a is short, while scrollbar b is larger. When I scroll to the end of Scrollbar a, the focus shifts to Scrollbar b and it starts scrolling. Is there a way to prevent this from happeni ...

What is the best way to integrate React-bootstrap with Typescript?

Currently, I have incorporated Typescript into my project alongside React-Bootstrap. However, I encountered a Lint error with the following code snippet: const renderSearchAddressButton = (): JSX.Element => { return ( <div className="sear ...

Building Custom Navigation for a Multilingual Website in Concrete5

I am trying to build a multilingual website using Concrete5 (v 5.7). My custom theme has the following page layout: Home |-en |--Frontpage |--Contatcs |-<language2> |--<Frontpage> |--<Contacts> The current navigation implementation is ...

Positioning the slider based on the width

I've created a slider on my website: However, I noticed that when I slide to the right, there is some space between the image and the edge of the container. Despite setting everything's width to 1100px, I can't figure out where this extra s ...

Using jQuery to restrict the number of checked checkboxes based on a selected value - Here's how!

How can I restrict the number of checkboxes that can be checked based on the selected option from a dropdown menu? For example, selecting 'option1' should allow only 1 checkbox to be checked, 'option2' should allow 2 checkboxes, and so ...

The glyphicons in Bootstrap are not appearing

My angular app is built using bulp angular and the component. I incorporate Sass (Node) into the project. I decided to switch to the flatly theme, which I downloaded from the bootswatch website and inserted it into _bootstrap.scss. // Core variables a ...

Creating a table with a static first column and vertical text positioned to the left of the fixed column

To create a table with the first column fixed, refer to this fiddle link: http://jsfiddle.net/Yw679/6/. You also need a vertical text to be positioned to the left of the fixed column in a way that it remains fixed like the first column. The disparities be ...

What is the best way to retrieve the name of a dynamic form in a Controller

How can I retrieve the dynamic form name in my controller? See below for the code snippet: HTML <form name="{{myForm}}" novalidate> <input type="text" ng-model="username" name="username" required/> <span ng-show="(submit & ...

Stopping the WordPress gallery at the end without looping using Elementor

Is there a way to make my gallery stop at the end of the last picture without having to add any jQuery code? I inserted this gallery using elementor widgets and would appreciate your help on this matter. Additional information: Upon clicking on an image, ...

Youtube no longer supports looping videos by adding "loop=1" to the URL

I'm trying to embed a YouTube video in my WordPress website with the loop parameter set to 1 so that it replays automatically. However, the video is not auto-replaying and instead showing related videos. Below is the HTML code I am using: <iframe ...

Determine a person's vertical measurement with jQuery

Is there a way to determine the distance from the top of the page to where a link has been inserted? For example, we can use the following code snippet to calculate the height of the window: w = $(window).height(); I am interested in finding out how to ...

What is the best way to stretch the background image across both the footer and navbar for my app?

Here is the code snippet I am currently working with: <template> <v-app> <AppBar></AppBar> <v-main> <router-view></router-view> </v-main> <Footer></Footer> ...

jQuery problem causes page to scroll when button is clicked

Is there a way to smoothly scroll to the second section of the page when a button is clicked using jQuery? $('.home_scroll_btn a').on('click', function(){ var scrollPosition = $('#intro-home').offset().top; $( ...

What is the best way to determine the width of a CSS-styled div element?

Is there a way to retrieve the width of a div element that is specified by the developer? For example, using $('body').width() in jQuery will provide the width in pixels, even if it was not explicitly set. I specifically need to access the width ...

What is the best way to create an iframe positioned above a navigation bar using CSS?

When I click the button, an iframe pops up on my website. However, the navbar overlaps it unless I scroll down. You can view my practice site at: This is the issue I am facing: https://i.sstatic.net/TKmw7.png Oddly enough, everything looks fine when I ...