Adjust the parent <div> border based on the content of its two child <div> elements

I am having trouble getting a border to wrap around my <div> element that contains two child elements. Currently, the green border is only showing at the top of the container and not all around it. Can someone please provide guidance on how to resolve this issue?

Below is the code snippet I have been working with:

.frame {
    border-style: solid;
    border-color: green;
    width: 500px;
}
.left {
    float: left;
    min-height: 20px;
    width: 200px;
    min-height: 20px;
}
.right {
    float: right;
    min-height: 20px;
    width: 300px;
}
.entry {
    height: 20px
}
<div class="frame">
    <div class="left">
        <div class="entry">
            key
        </div>
    </div>
    <div class="right">
        <div class="entry">
            value
        </div>
        <div class="entry">
            value
        </div>
        <div class="entry">
            value
        </div>
    </div>
</div>

Answer №1

Your .container div's height is collapsing because it only contains floated child elements. To fix this issue, you can add the following code to your .container class:

.container {
    overflow: hidden;
}

By using overflow: hidden;, you will create a block formatting context, which will ensure that block boxes interact with each other properly.

For more information, check out: Block formatting context

Answer №2

The issue lies in the frame not having a defined height due to all its children being floated. To resolve this, simply add overflow: hidden; to the frame class.

Answer №3

When utilizing the float property on child elements, it is crucial to remember to establish a layout on the parent elements as well. There are various methods for setting layouts. For instance:

.frame {
    overflow: hidden;
}

Another approach is to utilize the :after pseudo element:

.frame:after {
    content: '';
    display: block;
    clear: both;
}

.frame {
  border-style: solid;
  border-color: green;
  overflow: hidden;
  width: 500px;
}
.left {
  float: left;
  min-height: 20px;
  width: 200px;
  min-height: 20px;
}
.right {
  float: right;
  min-height: 20px;
  width: 300px;
}
.entry {
  height: 20px;
}
<div class="frame">
  <div class="left">
    <div class="entry">
      key
    </div>
  </div>
  <div class="right">
    <div class="entry">
      value
    </div>
    <div class="entry">
      value
    </div>
    <div class="entry">
      value
    </div>
  </div>
</div>

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

Switching background images with Javascript through hovering

I am currently working on implementing a background changer feature from removed after edits into my personal blog, which is only stored on my local computer and not uploaded to the internet. However, I am unsure of what JavaScript code I need to achieve t ...

"Which is better for maximizing the efficiency of an image grid: CSS or Jquery? What are the key

As a UX Designer looking to enhance my coding skills, I must admit my code may not be perfect. Please bear with me as I navigate through this process. I am in the process of revamping my portfolio website. The original seamless grid was created using a Ma ...

Ensure that all checkboxes are only selected within a single table

I have a challenge with selecting all check boxes in multiple tables when the header check box is selected. I am attempting to achieve this using jQuery without needing to parse or pass in the table id. Currently, when I select one header check box, all th ...

Data is not being displayed in the Angular table

Currently, I am working on developing a time tracking application as part of a project. However, I have encountered an issue while attempting to showcase all the entries in a table format (as shown in the image below). Despite having two entries according ...

Utilize JQuery to create expand and collapse functionality for a div

Trying to decipher the intricacies of this JQuery code has been quite the challenge for me. I would normally opt for a different approach, but it seems I must adhere to this particular method. My main issue lies in getting the functionality right - when cl ...

An issue arises when the closing tag is prematurely closed in JavaScript

This marks the first time I've ever posed a question on this incredible website. Typically, I can find the answers I need through some research here, but this time that isn't the case, so I'm reaching out for help. Here's the issue at ...

Filtering data from Arduino using web serial communication

My setup consists of an Arduino kit connected to a webserial API that sends data to an HTML div identified by the id 'target'. Currently, all the data is being logged into one stream despite having multiple dials and switches on the Arduino. Th ...

Creating responsive containers in Bootstrap 4 by adjusting sizes based on screen width and height

I've been scratching my head trying to crack this code. My goal is for the container size to always adjust based on the screen size. I attempted setting the height using min-height and max-height, however, it's not perfectly aligned with the scre ...

How to Position Buttons at the Bottom of a Card with Bootstrap

When creating a card for certain items, I am using the code below. To align the button at the bottom of the card, I have implemented the following: return ' <div class="col"> <div class="card detail ...

Ensure a consistent number of draggable elements in HTML/JavaScript

Below is the HTML/JS code snippet: <!DOCTYPE HTML> <html> <head> <script> function allowDrop(ev) { ev.preventDefault(); } function drag(ev) { ev.dataTransfer.setData("text", ev.targ ...

Utilize JavaScript to append a CSS class to a dynamic unordered list item anchor element

I am working with a list of ul li in a div where I need to dynamically add CSS classes based on the click event of an anchor tag. Below is the HTML structure of the ul li elements: <div class="tabs1"> <ul> <li class="active"> ...

What is the best way to ensure the email I send appears in Outlook Express exactly as it does in my web browser?

When I view this in my web browser, it appears correct. However, once I send it to Gmail or Outlook, the layout is no longer center-aligned like many other newsletters I receive. Here is the HTML code I am using: <form target="theFrame" > <DIV ...

Converting Arabic characters from HTML to PDF with iText

I have thoroughly searched every iText related topic regarding Arabic characters on various platforms, but I have not been able to find a solution for my specific issue. I am trying to convert an HTML file into a PDF, but the HTML content includes both Eng ...

ensuring that all items in the owl Carousel have equal heights

My current project involves creating an Owl Carousel. Here is the code I have implemented so far: <div class="owl-carousel owl-theme"> @foreach (var item in Model.Books) { <div class="item"> ...

Implementing a full-width search bar within the Bootstrap navbar

I'm trying to create a navbar using Bootstrap 3.7.7 with a logo on the left, links on the right in two rows, and a large search bar in the center. I've managed to align the logo and links correctly, but I'm struggling with sizing the search ...

What is the best way to enable this JavaScript function exclusively for a particular width?

Is there a way to make this javascript function active only when the screen width is at least 1070px? Currently, I have two different headers for screens smaller than 1070px, causing padding to be added regardless of the presence of "navbar_top". Can med ...

Is it possible to send a POST request to PHP without reloading the page

URGENT UPDATE - REQUESTING ASSISTANCE! ISSUE WITH POSTING DATA TO SQL SERVER WITHOUT PAGE REFRESH I have extensively searched online forums for a solution to my problem, but I keep encountering the same issue. My goal is to submit data without reloading t ...

The web page is not being fully displayed by IE 8

I'm struggling with a simple code snippet that is causing trouble in IE8 but works fine in Chrome. Here is the code: <style type="text/css> #header-cont { width:100%; background:#0080c9; backgrou ...

Issues with webpage responsiveness, width not adjusting correctly

Just completed coding my website and now I'm facing a new challenge. I am focusing on making it responsive for tablet screens (768px) starting with the header section, but for some reason, the modifications I make in the responsive.css file are not ta ...

Troubleshooting compatibility problems between jQuery UI Sortable and a responsive Bootstrap 5 page

Has anyone had experience using the jQuery UI Sortable widget on a Bootstrap 5 responsive page? My page consists of <div class="col-lg-6"> elements, displaying two per row. Although the sorting functionality works, I've encountered t ...