Is it normal for the section height to disappear when a container within a <section> is floated left?

I need help creating a website section with 3 containers aligned horizontally and a footer.

The containers are labeled with the class "box" and the footer is simply referred to as <footer>. The containers are nested within a section with the id "boxes".

After applying the property float: left; to the class "box", I noticed that the entire section with the id "boxes" disappears. However, the contents of the "box" class within the "boxes" section are still visible, but the <footer> seems to take over the entire region instead of just the "boxes" section.

Please refer to the image below for better understanding:

https://i.sstatic.net/5khY6.png

I would appreciate any advice on whether this behavior is normal and how I can achieve the desired style:

  1. 3 Containers aligned horizontally
  2. Footer at the bottom

Thank you!

P.S.: Below is a snippet showcasing the issue faced. Note how the <footer> seems to overpower the

<section id="boxes">
.

#boxes .box {

    text-align: center;
    float: left;
    margin-top: 20px;
    width: 30%;
      padding: 10px;
}

#boxes .box img {
    width: 90px;
}

footer {
    float: center;
    text-align: center;
    padding: 20px;
    color: white;
    background: orangered;
}
<section id="boxes">
    <div class="box">
        <h1>SMRT Logo</h1>
        <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHXhQgQJ6ky3JXZj-rCKJHjPXUJ6yynBkopg&usqp=CAU">
     </div>
     <div class="box">
        <h1>Pimentos Del Pardon</h1>
        <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHXhQgQJ6ky3JXZj-rCKJHjPXUJ6yynBkopg&usqp=CAU">
     </div>
     <div class="box">
         <h1>Tomato Plant</h1>
         <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQHXhQgQJ6ky3JXZj-rCKJHjPXUJ6yynBkopg&usqp=CAU">
     </div>
</section>

<footer>
    This is the fourth project &cc 2021
</footer>

Answer №1

float: center is not a valid CSS property. To make the footer clear the floating boxes, you should use clear: both. Here's how you can modify your code:

#boxes .box {
    text-align: center;
    float: left;
    margin-top: 20px;
    width: 30%;
    padding: 10px;
}

#boxes .box img {
    width: 90px;
}

footer {
    clear: both;
    text-align: center;
    padding: 20px;
    color: white;
    background: orangered;
}
<section id="boxes">
    <div class="box">
        <h1>SMRT Logo</h1>
        <img src="image-url-here">
     </div>
     <div class="box">
        <h1>Pimentos Del Pardon</h1>
        <img src="image-url-here">
     </div>
     <div class="box">
         <h1>Tomato Plant</h1>
         <img src="image-url-here">
     </div>
</section>

<footer>
    This is the fourth project &cc 2021
</footer>

Instead of using floats, consider using grid and flexbox for more modern layout options that are widely supported. Here's an example using grid layout:

#boxes {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
}

#boxes .box {
    text-align: center;
    margin-top: 20px;
    padding: 10px;
}

#boxes .box img {
    width: 90px;
}

footer {
    text-align: center;
    padding: 20px;
    color: white;
    background: orangered;
}
<section id="boxes">
    <div class="box">
        <h1>SMRT Logo</h1>
        <img src="image-url-here">
     </div>
     <div class="box">
        <h1>Pimentos Del Pardon</h1>
        <img src="image-url-here">
     </div>
     <div class="box">
         <h1>Tomato Plant</h1>
         <img src="image-url-here">
     </div>
</section>

<footer>
    This is the fourth project &cc 2021
</footer>

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

What is the best way to adjust the width of these elements for a perfect fit?

I'm currently working on a website where I have arranged squares in a grid layout. My goal is to make these squares perfect, with equal width and height. The only issue I'm encountering is that they tend to change between fitting two and three sq ...

What other aspects of mobile design could mobile-specific CSS be focused on aside from screen size?

As a newcomer to responsive web development, I have found myself puzzled by media queries. For example, how does the following code snippet target specifically iPhones with a max-device-width of 320px: @media screen and (max-device-width: 320px) {} Woul ...

What is the best way to trigger an onclick event for an input element with a type of "image"?

In the code I'm working on, there's an input of type "Image". <div class="icon" id="button_dictionary"> <form> <input class="buttonDictionary" type="image" src="icone_dicionario.jpg" value="" id="inputDictionary"> ...

Dynamic Rendering of Object Arrays in Table Columns using JavaScript

In the process of developing an appointment slot selection grid, I have successfully grouped all appointments by dates. However, I am facing challenges in displaying this array of Objects as a clickable grid with columns. The current output can be viewed h ...

Error code (6) occurred during the upload process on the Google Drive website, resulting in

I'm currently working on building a website that allows users to upload files directly to Google Drive from the website itself, but I've encountered numerous challenges in the process. Here's the code snippet I've been using: <!DOCT ...

How can I make the expired date display in red color in a JavaScript date property?

In my HTML, I have 4 different dates. The expired date "END MAR 20" should be displayed in red color instead of green. The next date, "END APR 29," should be in green color. All preceding dates should also be displayed in red. I have successfully filtered ...

Grow the Bootstrap column when hovered over (Similar to Netflix)

My grid view is structured as follows: jQuery(window).resize(function(evt) { jQuery(".grid-content > div > div > .channelImage").height(jQuery(".grid-content > div > ...

Vanilla JS method for resetting Bootstrap 5 client-side validation when focused

I'm currently exploring Bootstrap 5's client-side validation feature. However, I've encountered a usability issue with the is-invalid class. After clicking the submit button, this class persists until the correct input is entered. I would li ...

Floating point expansion caused by the addition of padding

Currently working on a basic 2 column layout design for a website, but ran into a hiccup. Whenever I try adding padding to the left-floated column, it ends up expanding beyond the width that I have set. Unfortunately, I haven't been able to find a sol ...

Tips for maintaining the cleanliness of PHP-generated HTML output in the 'View Source' option

I've been noticing a problem today while examining the source code on a website. I typically use PHP output in my templates to generate dynamic content. Initially, the templates are written in HTML only, with clean indentation and formatting. The PHP ...

Utilize AngularJS to create a custom tag with a directive included

I've been working on creating a custom tag for a reusable component in a web page, but I seem to have hit a roadblock. It's not functioning as expected, and I feel like I might be overlooking something. If anyone could provide some guidance or p ...

Populate the div with the URL parameter only when another span element is empty after a specified time interval using setTimeout

When displaying a person's name on a page, there are two different methods to consider. It can be extracted from the URL or retrieved from an email form in the CMS used. However, these two approaches sometimes conflict with each other. Currently, I h ...

Google Maps introduces a new feature that creates a blur effect on

Currently, I am utilizing the sample code provided below to superimpose an element on a Google map. <!DOCTYPE HTML> <html> <head> <title>Google Map Test</title> <style> html, body { margin: 0; ...

Activate hover effect on toggle button

When I hover over the "CHANGE" button, the orange color appears as expected. Clicking the button once turns the color red but removes the hover color, which is fine. However, clicking it twice brings back the original blue color but the hover effect is m ...

Is there a way to utilize the passValue function twice within Javascript?

Is there a way to display the value of an input field in multiple spots throughout the code? Currently, my code only passes it once. How can I rewrite it to show up again later in the code? //HTML: <input type="text" name="amount" onchange="passValue ...

What is the proper way to utilize a variable within the translate3d function?

Currently, I am developing my portfolio and working on a function in JavaScript called translate3d(0,10px,0). My question is, how can I use a variable instead of hardcoding the value 10px? I attempted to use translate3d(0,a,0) where 'a' is a vari ...

Tips for effectively utilizing an autocomplete input field with Vue that draws information from a database source

I am looking for a way to implement an autocomplete feature in my Vue application using data from a database table with over 3000 records. Here is how I am currently retrieving the data: data(){ return{ inboundRelation_Trelation_data: [], } ...

Looking to design an interactive grid for generating dynamic thumbnails

I am a beginner in the field of web development and I have a desire to create a website for showcasing my portfolio. This website should feature project thumbnails along with brief descriptions, all of which should be displayed dynamically. Although I poss ...

``Is there a way to position an image at the center in Python dash?

Can someone help me with centering an image in my Flask dash app? Here is the code I have: import dash from dash import html, dcc import dash_bootstrap_components as dbc app = dash.Dash(__name__) app.layout = html.Div([ dbc.CardImg(src=r'assets/ ...

Is there a way to streamline the process of uploading an image and storing its details in a single HTML form with just one submit button?

Here is the code snippet I have: <form id="registration_form" action="AddProductServlet" method="post"> <div> <label> <input placeholder="Product ID" name="pid" type="text"> ...