CSS - overcoming the challenge of border not extending over floated left elements

I encountered an issue with the following code:

<div style="border:3px solid #808080;">
    <h1 style="text-transform: uppercase;font-size: 38px;color: #808080;text-align: center;">Lowell</h1>
    <div class="column-1">
         <img src="images/ruler-icon.png">
    </div>
    <div class="column-2">
         <img src="images/bed-icon.png">
    </div>
    <div class="column-3">
         <img src="images/bath-icon.png">
    </div>
</div>

The border does not extend to cover column-1, column-2, and column-3 since these elements are floated left. How can I make them part of the border?

Below is the relevant CSS:

.column-1, .column-2, .column-3
{
    float:left;
    width: 33%;
    border-right: 3px solid #808080;
    height: 52px;
    padding: 10px;
}

Answer №1

To prevent overlapping, one solution is to insert a div in the parent element with the clear:both property immediately after the floated elements, as suggested by RemyaJ.

Example using the first method: https://jsfiddle.net/zmasvt8b/

Alternatively,

Another approach would be to apply the overflow:hidden property to the parent div.

Example using the second method: https://jsfiddle.net/jv5xtLg9/

Answer №2

While you may have already decided on an answer, I wanted to offer another option using flexbox and keeping the CSS separate from the HTML.

.container {
  /* Utilized for creating columns */
  display: -webkit-flex;
  display: flex;
}

.item {
  /* Helps create columns */
  flex-grow: 1;
  border: 3px solid #808080;
  border-top: none;
  height: 52px;
  padding: 10px;
}

.heading {
  border: 3px solid #808080;
  margin: 0;
  text-transform: uppercase;
  font-size: 38px;
  color: #808080;
  text-align: center;
}


/* To eliminate duplicate borders */
.item-2 {
  border-left: none;
  border-right: none;
}
<h1 class="heading">Lowell</h1>
<div class="container">

  <div class="item item-1">
    <img src="images/ruler-icon.png">
  </div>

  <div class="item item-2">
    <img src="images/bed-icon.png">
  </div>

  <div class="item item-3">
    <img src="images/bath-icon.png">
  </div>
</div>

Answer №3

To resolve the problem, insert a div with the CSS property clear:both following the floated elements within the containing div.

Answer №4

Here is the CSS that may suit your requirements. Adjust the width as necessary.

.box1, .box2, .box3
{
    width: 25%;
    border-left: 4px solid #909090;
    height: 60px;
    padding: 12px;
    display:inline-block;
}

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

Using Selenium in Python, loop through webpages to extract the search result position

Currently, I am using a script to search for a generic keyword and determine the rank of my products on an e-commerce platform. The code below has been working successfully in fetching the product ranks on the first page. from selenium import webdriver dr ...

Python script for connecting to mWebSocket Server using WebSocket client

I am in the process of developing a WebSocket client using python that establishes a connection to an Arduino Uno via an Ethernet cable every second. The Arduino Uno is equipped with a WebSocket server using the mWebSocket library. The operational code for ...

Using jQuery to modify the CSS of a div located outside of an iframe

Currently, I am developing a straightforward script. Firstly, here is all of the code that I have: <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script type="text/javascript"> function SuperWebF1() { $("#outerd ...

Tips for customizing the event target appearance in Angular 2?

After following the steps outlined in this particular blog post (section 3, event binding), I successfully added an event listener to my component class. I can confirm that it responds when the mouse enters and exits. <p class="title" (mouseenter)="unf ...

The most effective way to align text in a right-to-left language is by utilizing the text-align property with a

If the project is in a right-to-left language (such as Persian or Arabic), which method is preferable for setting text-align: right and direction: rtl? Option 1: Implement globally, for example: body * { direction: rtl; text-align: right; } ...

Turn off dropdown menu animation (JavaScript)

I am trying to completely disable the transition effect on my drop-down menu. Below is the JavaScript code that I believe needs to be changed: function(e) { if ((/input|textarea/i.test(e.target.tagName) ? !(32 === e.which || 27 !== e.which && (40 !== e ...

Issue with Bootstrap 4 nav bar where the first nav item is not highlighted and a problem with scrollspy

I have encountered an issue that I need help resolving. My Bootstrap 4 navbar has scrollspy enabled to update as you navigate through the page's sections, and a jQuery function provides smooth scrolling when clicking on navigation links. However, I am ...

How to make external links open in a new window within wagtail

Recently, I made a change to include target="_blank" in external links by implementing the following code: @hooks.register('after_edit_page') def do_after_page_edit(request, page): if hasattr(page, "body"): soup = BeautifulSoup(page. ...

Ensure that buttons are cropped when extending beyond the border of another DIV

My issue involves a main DIV with buttons contained within it. I am seeking a solution to ensure that the buttons are cut off at the edge of the DIV, similar to the concept illustrated in this image. In the image, the blue represents the body, the light gr ...

What is the purpose of using "recaptcha_get_html" function to echo?

Hello everyone. I've been struggling to incorporate Google's reCAPTCHA into my project and I keep encountering an error when trying to use the recaptcha_get_html function. It keeps showing up as undefined and despite searching high and low, I can ...

Ways to eliminate flickering when dynamically updating iframe content

Currently, I am in the process of constructing an iframe slideshow that consists of 7 webpages named event1.html to event7.html. To implement the automatic changing of the iframe source every 1 second, I am utilizing setInterval. However, I am facing an is ...

What could be the reason for the individual components not being populated within the listItem?

*** I am iterating through an array and calling the ListItem component for each item. However, only one ListItem is being populated when there should be 3. Can someone please help me figure out what's wrong? *** Here is my code in App.js *** import F ...

Implementing Material-UI’s FlatButton and Dialog in ReactJS for dynamic TableRow functionality

I am working with Material-UI and have implemented a <Table> component. Each dynamically rendered <TableRow> in the <TableBody> needs to include a button (<FlatButton>) within one of the columns. When this button is clicked, a <D ...

Attempting to dynamically generate a delete button and execute the delete function using JavaScript

On this page, I aim to load the 'skills' from my java application and dynamically generate a Delete button that allows me to remove those 'skills' from the application. An error occurs when trying to click the button to delete a skill. ...

Repeatedly view the identical file on HTML

I'm currently working with the following HTML code: <input type="file" style="display: none" #file(change)="processImage($event)" /> <button type="button" class="btn" (click)="file.click()" Browse </button> When I select image1 fr ...

Does the media query max-width refer to the size of the viewport or the size of the window?

Can someone clarify whether the max-width in a media query is based on the viewport size or window size? For instance, consider this media query: @media screen and (max-width: 360px){} Would this media query be activated when the viewport reaches 360px ...

What is the best way to collect and store data from various sources in an HTML interface to a Google Spreadsheet?

Currently, I have a spreadsheet with a button that is supposed to link to a function in my Google Apps Script called openInputDialog. The goal is for this button to open an HTML UI where users can input text into five fields. This input should then be adde ...

After refreshing, a blank page appears when using the HTML POST method

After conducting a test using an HTML form with the POST method, I encountered an unexpected outcome. The setup involved two HTML pages hosted on an Apache server (with PHP already installed): post.html and target.html. Below are the code snippets for thes ...

What types of devices are compatible with the different versions of the Android operating system?

I am currently working on a jquerymobile application for Android versions 2, 3, and 4, as well as iPhone, iPad, and iPod touch. I am analyzing user-agent strings using jQuery and jquerymobile. After testing with an emulator, I have noticed that all device ...

Differences between using tables and divs for form layouts

After searching online for examples of form implementations using DIVs, I noticed that most were simple one-column forms. However, my forms are more complex, like the one shown in this image: Although I can easily create these forms using tables, I encoun ...