Two adjacent divs merge into the following div

Hey everyone, I'm facing an issue that I can't seem to figure out. I know it's probably something very simple, but as a beginner, I'm struggling...

Every time I use the float:left command, the elements with classes .con-icon and #con-info escape the boundaries of the container #contain and overlap with the next div called #test (the one in dark red). How do I make sure they stay within the borders of #contain?

You can find the code here: http://jsfiddle.net/3eoj06b3/.

<section id="contain">
    <h1>Contain</h1>
    <div id="con-info">
        <div class="con-icon">
            <h2>1</h2>
            <h2>1</h2>
            <h2>1</h2>
        </div>
        <p>2</p>
        <p>2</p>
        <p>2</p>
    </div>
    <div id="test"></div>
</section>

The CSS code is provided in the link.

I'd appreciate any help or suggestions on what could be potentially causing this issue. Thanks!

Answer №1

Make sure to include the following snippet in your CSS code:

#container-information:after {
    content: " ";
    display: block;
    clear: both;
}

Answer №2

To ensure your parent element is aware of its floated children heights, simply include the line overflow:auto; in your #con-info class. Check out this example on http://jsfiddle.net/examplelink/.

Answer №3

To ensure the automatic height of #con-info, apply the CSS property overflow: hidden to it. This will work in conjunction with the existing declaration of height: auto for #con-info.

Check out the demo here

#con-info {
    overflow: hidden; /* Added for automated height */
    position:relative;
    border:2px solid #C60;
    width:40%;
    height:auto;
    margin-left:10%;
}

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

Tips for concealing all items except the currently selected branch when clicking on a menu drop-down

I am seeking a solution to open only one node at a time on click, and remove the 'is-active' class from other items. Currently, there is excessive space taken up after opening multiple menu items. I want to ensure that only one node is open at a ...

How can I make CSS text-overflow ellipsis trigger a pop-up to display lengthy text when clicked?

I'm encountering an issue with a lengthy sentence in a table cell which I've truncated using text-overflow to display ellipsis. Is there a way to enable users to click on the dots (...) and view the full text in a popup window? table { wi ...

Links in the navigation bar can be clicked on, however they are not visible when

The screenshot of the error The menu links in the mobile view aren't visible but clickable. As a novice in HTML and CSS, I'm facing an issue where the hamburger menu with z-index 1 is displayed correctly, but its content is not visible. This prob ...

Tips for preventing the appearance of two horizontal scroll bars on Firefox

Greetings, I am having an issue with double horizontal scroll bars appearing in Firefox but not in Internet Explorer. When the content exceeds a certain limit, these scroll bars show up. Can someone please advise me on how to resolve this problem? Is ther ...

The content is unclipped with a border-radius and hidden overflow

As I work on incorporating stylistic text inside rounded divs, I encounter a challenge where the text touches the top of the container. While I have successfully managed to customize various content elements such as nested divs and background images, this ...

The Ember.run.throttle method is not supported by the Object Function as it does not have a throttle method within the Ember.Mixin

I have a controller that has an onDragEvent function: controller = Em.Object.create( { onDragEvent: function() { console.log("Drag Event"); } }); Additionally, I have a Mixin called 'Event': Event = Ember.Mixin.create( { at ...

Struggling to make my JavaScript function work across different products

As a beginner in Javascript, I am facing an issue with a button that should open a 'window' when clicked. While it works for product 1 (chili oil), the same functionality is not working for product 2 (raspberry ratafia). Initially, the function ...

To verify if the given input value matches any of the options, then mark the checkbox

My script is functional, but I believe there's a more efficient way to handle it using an if statement. However, I've been unsuccessful in getting it to work. I am attempting to create a search function that checks if the value is 2, 3, or 5. If ...

obtaining extra space in the final portion of a table cell

I've been attempting to place the image and text next to each other, but I couldn't figure out how to make the image adjust its size (height & width) to fit into the table cell. Additionally, there seems to be extra space and the background color ...

What causes the variation in the appearance of the navigation bar across different pages?

I'm struggling to understand why the Navigation bar has extra padding or margin on top only on certain pages, while it looks fine on the Homepage. I've dedicated countless hours to this issue and I am feeling completely frustrated. If you' ...

Leave your thoughts with HTML and Javascript coding

Currently, I am working on developing a comment box feature using HTML and JavaScript. I have encountered a question regarding how to implement a delete functionality for comments using a button. Would it be more efficient to utilize a linked list struct ...

Update the src attribute in an HTML document

I am looking to dynamically change the size of an image on an HTML page using a dropdown list. Here is my code: <html> <head> </head> <body> <select id="selectbox" name=""> <opti ...

Overflow issues with flexbox design on mobile devices

Hello, I'm currently working on creating a sliding panel of images. While I have successfully implemented it, I am encountering some browser compatibility issues. The sliding panel functions perfectly on Chrome desktop, however, when viewed on mobil ...

Dynamic resizing of Bootstrap Carousel

As I delve into the realm of web design, I've encountered a puzzling issue with my BootStrap Carousel on a website project. Despite copying the code directly from the BootStrap 5.1 carousel documentation page, its behavior is rather odd, and I'm ...

Step-by-step guide on crafting a scrolling marquee with CSS or Javascript

I am in need of creating two marquees for a website project. The first marquee should showcase a repeating image while the second one should display links, both spanning the browser window at any size. It is crucial that the marquee items are displayed fro ...

The dropdown feature in the pug navigation bar is malfunctioning

The navigation bar at the top of the page is not functioning properly when attempting to access the drop-down menu items (Items, Brands, or Categories). The drop-down options fail to open on click. Screenshot of Navigation Bar Pug file: doctype html html ...

Converting Excel values to Exponential format using Python

I'm struggling to find a solution for extracting the Invoice Number in Python from an Excel sheet without turning it into exponential form. Expected Value: 8000030910 Result: 8.00002e+09 Python Result Excel sheet d1.append(sheet.cell_value(j,0)) ...

Guide on making a button for adding products to the shopping cart

I have put together this web page Check out the views.py code below: from django.shortcuts import render from django.http import HttpResponse from .models import Pizza # Managing views here. def index(request): pizzas = Pizza.objects.all().order_by( ...

Having an issue with deleting a table row using jQuery when the button is clicked

I am facing an issue where clicking on a button does not delete the table row despite both the tr id and button id having the same value. Can someone please guide me on what might be going wrong? <tr id="<?php echo $result->id;?>"> <t ...

Troubleshoot redirect issues in JavaScript or PHP

I am facing a simple issue that is proving to be time-consuming to solve. The challenge that I am encountering involves an HTML form with 2 buttons. Here is the relevant code snippet: $html1 = "<div class='pai-forms'> <form ...