Images on a webpage can cause the height of a div element to remain

I've encountered a problem with displaying 5 images horizontally on the screen. For some reason, I'm unable to set the height of the Div "block-before-description". In FireBug, the height appears as 0 while the 20px margin is visible. Despite trying various methods such as floating, display:block, and different positioning options, including absolute/relative, I haven't been able to resolve the issue. Interestingly, when I remove the images and leave only the headings, the block shows the correct height to cover the headings.

<style type ="text/css">
    .container {
      margin-right: auto;
      margin-left: auto;
      padding-left: 15px;
      padding-right: 15px; }

    .col-md-2 {
        float: left;
        width: 16.66667%;
        position: relative;
        min-height: 1px;
        padding-left: 15px;
        padding-right: 15px;
        }

    .feat-icons {
      text-align: center;
    }

    .block-before-description {
      margin-bottom: 20px;
      padding: 0px;
    }
</style>

</head>

<body>
<div class="container">
    <div class="block-before-description">
        <div class="col-md-2 feat-icons">
            <img src="icons/30-Days-Support.jpg" width="105" height="105" alt=""/>
            <h4>Support</h4> 
        </div>
        <div class="col-md-2 feat-icons">
            <img src="icons/Design-Icon.jpg" width="105" height="105" alt=""/>
            <h4>Premium Design</h4> 
        </div>
         <div class="col-md-2 feat-icons">
            <img src="icons/Features.jpg" width="105" height="105" alt=""/>
            <h4>Features</h4> 
        </div>    
         <div class="col-md-2 feat-icons">
            <img src="icons/Guide-Icon.jpg" width="105" height="105" alt=""/>
            <h4>Guide Included</h4> 
        </div>     
         <div class="col-md-2 feat-icons">
            <img src="icons/Mobile-Icon.jpg" width="105" height="105" alt=""/>
            <h4>Mobile Supported</h4> 
        </div>
    </div>

</div>

</body>
</html>

If anyone has any insights or solutions to this issue, please feel free to share. Any help would be greatly appreciated.

Answer №1

This issue arises from the common problem of the children within containers floating. Consequently, the parent's height is not properly calculated due to the children being taken out of the natural document flow.

For the solutions provided below, we will not delve into Bootstrap's pre-made fixes as your inquiry did not reference Bootstrap.

An easy fix is to utilize the overflow property on the parent element:

See an example demonstrating overflow and float properties.

.block-before-description {
  margin-bottom: 20px;
  padding: 0px;
  background: #F00;
  overflow: hidden;
}

Alternatively, you can opt for not using floats altogether and employ display: inline-block for aligning images in a single horizontal line.

View a demonstration utilizing inline-block display.

 .col-md-2 {
    display: inline-block;
    vertical-align: top; /* choose middle, top, or bottom for consistent alignment */
    width: 16.66667%;
    position: relative;
    min-height: 1px;
    padding-left: 15px;
    padding-right: 15px;
 }

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

Updating a webpage's background image using Jquery and PHP every 10 seconds

I am in the process of designing a webpage for my hobby radio station. Currently, I have the artist and title displayed, but I would like to take it a step further and have the background change based on the artist playing. For example, when Phil Collins i ...

Is it possible to resize a Div using pure CSS?

Here is the HTML structure I am working with: <div class="outer"> <div class="inner"> <a href="#"/> <a href="#"/> <a href="#"/> </div> </div> This is the corresponding CSS: div.outer{ position:relative; ...

What is the best way to have a flexbox item occupy the available space and enable scrolling?

Trying to create a vertical scrollable div within the remaining space of various elements that do not have fixed heights. I currently have a flexbox element that adjusts to its content, but what I actually need is for the element to fill up the empty spac ...

One cannot focus on HTML if it's disabled

I am currently exploring options to prevent an input from receiving focus without disabling it entirely. I need the backend to still retrieve data, but I want to restrict user editing of the input fields at certain times. Disabling the input is not an opti ...

Create a Bootstrap grid that perfectly fits the viewport without any overflowing content

I'm currently utilizing Bootstrap 5 in an attempt to design a simplistic layout consisting of an MxN grid of cells, each of equal size. My goal is to have this grid fill the entire viewport without any scrollbars appearing in either direction. However ...

The DIV element fails to encompass all of its content

There seems to be an issue with the only div element on my page. It's covering the middle of the page, but I managed to make it extend all the way down using CSS tweaks. However, there is a problem - the video inside the div is overflowing: Below is ...

Issue encountered with ngFor: 'Identifier not defined __type does not have any such member'

Recently, I successfully implemented a sub-component that allows users to dynamically add and remove a set of controls to and from a collection. The inspiration for this solution came from reading through this particular thread on Stack Overflow. While ev ...

[Web Development]:

Having an issue with my HTML file where a JavaScript function named "CheckCaptcha" is not being executed when an image is clicked. I've been working on the code for hours, trying different tweaks and modifications, but it still can't seem to find ...

The view of the Google map is filled with numerous rounded tiles

Map divided into 3x3 tiles I am looking to customize the appearance of my map and remove all spaces and rounded corners to create a seamless, undivided visual. Is there a way to modify a map tile attribute to achieve this effect? Below is the code snippet ...

Want to learn how to create a draggable uploaded image on a canvas, similar to the functionality of Google

I have a question regarding the draggable feature in Canvas elements. I uploaded an image into the canvas and would like it to be draggable, similar to Google Maps. My ultimate goal is to enable zoom in and out functionalities as well. Is this achievable ...

Creating an HTML template in an Angular service and utilizing it as an HTMLTemplateRef

I'm currently working on a major project that has a specific requirement. As part of this project, I am utilizing a library which allows me to open dialog (modal) popups. In order to do so, I need to configure some options for the modal opening proce ...

Determine if a draggable item is currently positioned over another element

In my body, there are several divs located: <div id="one"></div> <div id="two"></div> <div id="three"></div> All of these divs are draggable using jqueryUI: var $divs = $('#one, #two, #three'); $divs.draggab ...

Design a unique border for a div element that extends a top-border all the way through the header and a bottom-border that

I am trying to achieve the design displayed in this mockup: https://i.sstatic.net/sYEPu.png Here is my current progress: https://codepen.io/raney24/pen/VOmjBY .header-border { width: 100%; margin-bottom: 10px; border-left: red solid 1px; border ...

Changing the appearance of your website on various pages using WordPress: activating unique stylesheets

When connecting my stylesheets to my WordPress theme, I include the following in my customtheme/style.css file: @import url('bootstrap/bootstrap.min.css'); @import url('includes/styles1.css'); @import url('includes/styles2.css&ap ...

Hierarchy segment for CSS selection

I have a rather unique query. How can I create a selector that targets a specific part of the hierarchy based on classes? For instance, I'd like to select something like: <node class="start-selection"> <node> <n ...

Unusual shift in the modal's behavior occurs when the parent component's style.transform is applied

I have encountered an unusual issue with a modal's appearance and functionality. The modal is designed to enlarge images sent in a chat, with the chat upload preview div serving as the parent element and the modal as the child element. This strange be ...

The image is not appearing on mobile devices, but it is displaying correctly on desktop computers

Having trouble with my landing page on compare.comxa.com. When I try to view it on my Android device, only the form shows up and the background image is nowhere to be found. Can anyone help me troubleshoot this issue? Here is the code: ...

Version 3 of Source Maps and CSS compilation/compression

Is there a tool available that can compress, minify, and combine CSS files while generating a valid v3 SourceMap compatible with Chrome? Ideally, I am looking for a NodeJS tool. From my research, some Node compressors like clean-css, csso, css-condense (w ...

Tips for preventing breaks in typography

I have implemented a material ui Typography component, but it's causing a line break even though there is enough space. Here is the code snippet: <Box flexDirection="row"> <Typography> Gender: <RadioGroup row ...

Determine if a certain value is present in an array within an HTML document

In the context of AngularJS, I have an array that looks like this: var test=["abc/1/1","def/2/2","efg/3/3"]; I am trying to determine if the array contains a value with "abc" in it within my HTML code. When I used the following: test.indexOf("abc")!=-1 ...