How can I avoid floating content from overlapping in two div elements?

I am currently working on creating a FAQ page and have implemented the following structure:

<section id="container">

     <div id="faq_primary"></div>
     <div id="faq_sidebar"></div>

</section>

<footer>

     <div id="directory">

          <div id="col_a"></div>
          <div id="col_b"></div>
          <div id="col_c"></div>

     </div>

</footer>

Below is the CSS related to this content:

#container {
    width:960px;
    margin: 0px auto;
    position:relative;
}

#faq_primary {
    width:720px;
    margin:20px 40px 0 0;
    position:relative;
    float:left;
    display:inline; 
}

#faq_sidebar {
    left:760px;
    position:absolute;
}

footer {
    width:1111px;
    height:250px;
    margin:90px auto 0px;
    position:relative;
    background-image:url(../images/footer/bg.png);
    color:#7d7d7d;
}

#directory {
    width:960px;
    margin:0px auto;
    padding-top:25px;
    font-size:13px;
}

#directory ul li{
    padding-bottom:4px;
}

#dir-cola, #dir-colb, #dir-colc, #dir-cold, #dir-cole {
    width:174px;
    height:140px;
    float:left;
}

#dir-cola {
    width:150px;
}

#dir-cole {
    width:143px;
}

The main content of my page is within the container section, with the footer positioned directly below. The faq_sidebar is shorter than the faq_primary, causing the columns in the footer to align to the right of the faq_primary and below the faq_sidebar.

Attached is a screenshot for reference:

Any suggestions on how I can prevent the content in the footer and container from overlapping?

Answer №1

It's difficult to determine without having the exact same content, as my attempts do not result in matching the screenshot due to differences in content.

However, I am confident that if you add the following CSS rule:

#container
{
    // ... *snip*
    overflow: hidden;
}

This will cause the container to factor in the height of the floated children when calculating its own height.

I also recommend changing the sidebar’s left: ... property to right: 0 if you want to position it on the right side (or consider using float: right instead of absolute positioning).

EDIT:- After noticing a similar answer in another question, I suspect this may be a duplicate. Question: Make outer div be automatically the same height as its floating content

Answer №2

Consider inserting a clearing div at this point

<div id="faq_sidebar"></div>

<div class="clear"></div>

</section>

You should then apply the following styling to it

.clear{
    clear:both;
}

If this doesn't solve the issue, try placing it after the closing </section>

Answer №3

clear:both;
clear:left;
clear:right;

These properties are utilized to control and prevent the image from overlapping with the adjacent div or image on either the right or left side.

Answer №4

If you have a setup like this inside a container:

<section id="container">

<div id="faq_primary"></div>

<div id="faq_sidebar"></div>

</section>

and you prefer them to be displayed inline, consider adding the style display: inline to #container. The overlapping of footer content may be due to your use of absolute positioning for #faq_sidebar.

Answer №5

Delete the CSS property left:760px; from the selector #faq_sidebar.

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

Customizing the appearance of the browser's autocomplete feature as we input information into the form field

https://i.sstatic.net/p7PvH.png The image illustrates the issue of the background turning white when the browser autofills. However, I am seeking a solution similar to the transparent input below. ...

I need my styled component to make sure my inner div spans the entire width of its parent div

I'm having an issue with my NavDiv styled component not taking up the full height of my Wrapper styled component. I've tried setting the height using different units like percentage, em, rem, but it doesn't seem to work. It only works when u ...

Methods for automating the clicking of a hyperlink within Bootstrap tabs programmatically

I am attempting to programmatically trigger a click event on a specific href link within Bootstrap tabs. For reference, here is the link to the codepen: linkToCodePen <ul class="nav nav-tabs" id="myNavTabs"> <li class="active">&l ...

What is the best way to incorporate tailored validation into reactive forms in Angular?

I'm facing an issue with my form where I'm trying to display a specific error message based on certain conditions. Currently, my form is functioning but it's throwing a type error stating "undefined is not an object". I'm struggling to ...

Reset button for jQuery form to clear all inputted values

My form has a reset button that is supposed to clear all entered values, but it doesn't seem to be working properly. After checking the Firefox console tab for errors, I noticed an 'illegal character' error at the end of my jQuery script. C ...

Styling and theming in PrimeNG

Seeking advice on how to customize the appearance of the background for the primeNG panel component. I attempted to override the styling using the specific names in my scss file for the component, but it did not work. I also tried inline with <p-panel ...

What could be causing my select tags to appear incorrectly in Firefox and IE?

With the help of Jquery, my goal is to dynamically populate a select field when it is in focus, even if it already has a value. Once populated, I want to retain the previous value if it exists as an option in the newly populated field. Although this works ...

Add class or id dynamically when clicked

How can I dynamically change the CSS color of a roller-banner div based on user input? I have a codepen setup where I want to capture the class of the clicked element (e.g. colour3), and then apply that as an ID or class to the roller-banner div. Codepen ...

Combining HTML/CSS to overlay text on an image - EMAIL

Why does Google keep stripping my <style> tag when I try to overlay text on an image? I want the image to be on the left with two text blocks positioned over it on the right (one higher and one lower). It looks fine visually, but when I send it to m ...

Image expansion

I have a container element div that holds various content of unknown length. How can I add a background image that extends the entire length of the container since background-images do not stretch? I attempted to use a separate div with an img tag inside. ...

jQuery Slider not appearing on the page

I am attempting to incorporate the Basic jQuery Slider into my website. Below is the code I have used: For HTML file: <div id="slides"> <ul class="bjqs"> <li><a href="somelink"><img src="someim ...

Tips for customizing the appearance of a disabled checkbox

I'm curious if you have any ideas on how to customize the appearance of a disabled checkbox? For example: <input type="checkbox" value="All Terrain Vehicle" name="exfilter_All Terrain Vehicle" id="exfilter_All_Terrain_Vehicle" ...

Updating React JSX class based on certain conditions without manipulating the actual DOM

When working with jsx react, I am looking to dynamically set a class while keeping another class static. Here is an example of what I would like to achieve: maintaining the type class and having an additional dynamic class change change to either big, smal ...

What is the purpose of the hidden tag that accompanies a checkbox?

Similar Question: ASP.NET MVC: Why is Html.CheckBox generating an extra hidden input? While working on an asp.net mvc project, I noticed that when rendering a checkbox control, it also generates an additional hidden field like the examples below: < ...

Footer mysteriously appears on top of the container

Trying my hand at practicing HTML by creating a small webpage, but struggling with why the Footer is aligning itself under the Header instead of the container I set up. It seems like a small detail that I might have missed, but I've hit a wall and ca ...

Swap the existing div with a fresh div using jQuery or JavaScript

Seeking a straightforward method to swap out a div with a different div, ensuring cross-browser compatibility with JavaScript or jQuery. Below is a code snippet to demonstrate. The goal is to replace "myDiv-B" with a new div: <div id="myDiv-C">{% in ...

"Encountered an issue with submitting the nodejs form

edit 2 After attempting to implement the following code snippet in my nodejs application, I encountered an issue where the form data was not being successfully posted to the database: router.get('/dashboard/users/forms/competition-form/:id', en ...

Concealment Based on Surroundings

I'm currently working on implementing a new feature called 'context-based hiding' which involves hiding content based on mouse actions. I've been struggling to figure out how to create this feature and came across a website that has it ...

Adding a combination of HTML and Javascript to an element can result in unexpected behavior

http://jsfiddle.net/PeKdr/ Encountering an issue when having a JavaScript variable that contains both HTML and JavaScript, resulting in unexpected behavior in the output window. Neither of the buttons - one triggering the function appendTheString() or the ...

Tips on leveraging state values within the makeStyles function in Material UI React

I'm in the process of building a Webpage and incorporating Material UI for the Components. Here's the code: import { makeStyles, Typography } from "@material-ui/core"; const useStyles = makeStyles((theme) => ({ container: { ...