Ensure the child element is completely visible when it exceeds the size of its parent

I am facing an issue with a footer div that contains various other elements, one of which is an image that exceeds the height of the footer container. The image is not displaying completely as it is being cut off by the parent div (footer).

My goal is to achieve this with two specific criteria:

  1. The height of the footer should remain unchanged and not expand to accommodate the taller image.
  2. All elements within the footer should align at the bottom.

Here's what I have tried so far, along with the code on JSFiddle

HTML

<div class="wrapper">
    <div style="height: 100px; width: 80%; background: white;">BODY</div>
    <div class="footer">
        <div class="block-foot-social"> 
            <img src="http://placehold.it/10x10" />
            <img src="http://placehold.it/10x10" />
            <img src="http://placehold.it/10x10" />
            <img src="http://placehold.it/10x10" />
            <img src="http://placehold.it/10x10" />
        </div>
        <div class="block-foot-contact">
           <span>1-888-555-5555</span> | <span><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8fdceee3eafccfcaf7eee2ffe3eaa1ece0e2">[email protected]</a></span>
        </div>
        <div class="block-foot-icon"> 
            <a href="#">
                <img src="http://placehold.it/80x80" />
            </a>
        </div>
    </div>
</div>

CSS

.wrapper {
    height: 300px;
    background: blue;
}
.footer {
    clear: both;
    height: auto;
    width: 100%;
    overflow: auto;
    background: green;
    position: relative;
}
.block-foot-contact, .blook-foot-icon, .block-foot-social {
    float: left;
    margin: 6px;
    overflow: auto;
}

.block-foot-icon {
    position: absolute;
    background: red;
    overflow: visible;
    bottom: 0;
    right: 0;
    width: 150px;
}

I attempted removing overflow: auto from .footer, but this caused the collapse of the footer div and disrupted horizontal alignment. How can I resolve this issue? Thank you for your assistance.

Answer №1

If you're looking to have the image displayed in full without affecting the height of the footer and align everything at the bottom, check out my solution below:

Take a look at the CSS:

.footer {
    position: relative;
    background-color: green;
}

.block-foot-social,
.block-foot-contact,
.block-foot-icon {
    display: inline-block;
    vertical-align: bottom;
    width: 33.33333%;
}

.block-foot-icon img {
    position: absolute;
    bottom: 0;
}

To implement this solution, ensure there is no whitespace between the <DIV>'s in your markup, like this:

<div class="block-foot-social"> 
    <img src="http://placehold.it/10x10" />
    ...
</div><!-- no whitespace here --><div class="block-foot-contact">
    <span>1-888-555-5555</span> | <span><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="095a68656c7a494c71686479656c276a6664">[email protected]</a></span>
</div><!-- no whitespace here --><div class="block-foot-icon">
    <a href="#">
        <img src="http://placehold.it/80x80" />
    </a>
</div>

You'll also need to adjust the provided CSS by modifying widths and margins for each block according to your preferences.

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 Angular 2 to toggle the visibility of a component when hovering over and moving away from it

I have developed a custom filtering component in Angular 2, which I have integrated into the table header. My goal is to show the filter when the mouse hovers over a specific span, and hide it when the mouse moves away. <th> <span class="headCol ...

Ways to have a list component smoothly descend when a dropdown menu is activated

I have a situation where I have a list with two buttons, and each button triggers the same dropdown content in a sidebar component. The issue is that when I click on one button to open the dropdown, the second button does not move down to make space for it ...

The full height of the image cannot be captured by html2canvas

It baffles me that html2canvas is failing to capture the full height of the div. html2canvas($container, { height: $container.height(), onrendered: function(canvas) { var data = canvas.toDataURL('image/png'); ...

Organize items without consideration of their dimensions

I am in the process of creating an alphabetized list of categories, from A-Z. I am utilizing ul and li elements to achieve this. My goal is to have the elements displayed consecutively, regardless of their height. While my current code successfully arrange ...

Utilizing JavaScript, create a dynamic grid gallery with Div Spin and expand functionality

I am looking to create a unique effect where a div rotates onclick to reveal a grid gallery on the rear face. Starting this project feels overwhelming and I'm not sure where to begin. <ul class="container-fluid text-center row" id=" ...

What is the best way to distribute stroke width evenly on a rounded hexagon in an SVG?

I created a rounded hexagon with stroke width, but the top and bottom curves appear darker. Does anyone know how to evenly distribute the stroke width along the border? Here is my SVG code: <svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewbox ...

No JavaScript needed: Create custom overflow/scroll indicators using CSS only

Is there a way to align the content of a box to the left when the box doesn't overflow? I have a scroll indicator created with CSS only, which works well but has this alignment issue. Any suggestions or improvements on the code are welcome :) html ...

Beginner in CSS wanting to set background image for input field

I am working on incorporating icons into my project. The image I have contains an array of 16x16 icons at this URL: "http://www.freepbx.org/v3/browser/trunk/assets/css/jquery/vader/images/ui-icons_cd0a0a_256x240.png?rev=1" Does anyone know how I can selec ...

Taking out the z-index from the transition code

Is there a way to restructure the code without needing to use z-index for the transition? Without z-index: https://jsfiddle.net/Legcb42d/ .container1 { position: relative; width: 100%; height: 100%; } .container1.slide { height: auto; min-heigh ...

Tips for maintaining consistent content length of nested divs as one div's content grows

I am looking for a solution to ensure that when the map is running on my MUI card, some cards with more text content will increase in length while maintaining equal text alignment. I have attached a screenshot of my actual app and a CodeSandbox example for ...

Shift the plus-minus icon on the bootstrap accordion all the way to the right side

I'm struggling to adjust the position of the plus-minus icon on a Bootstrap accordion to the far right, but my current code isn't producing the desired result. Here's the CSS snippet: .mb-0 > a:before { float: right !important; ...

How to center content vertically in a Bootstrap 5 column div

I assumed that aligning content vertically in a div should be easier compared to using a table: Edit: I want to align the first and last columns while keeping the others as they are. <link href="https://cdn.jsdelivr.net/npm/&l ...

Unable to expand Bootstrap navbar due to collapsing issue

I recently implemented a collapsed navbar on my website using bootstrap. However, I'm facing an issue where it does not open when clicking on the hamburger menu. After researching various solutions for this problem and trying them out, none of them s ...

Adaptive search bar and components housed within a casing

I am struggling to create a responsive box with a search feature for a mobile website. My plan is to incorporate jquery functions into the site, so I need to design an outer container that will house a distinct logo and search bar. However, when I test thi ...

CSS transition not working properly when toggling

I am working on creating a toggle feature for a div that can expand and collapse upon clicking. While I have successfully implemented the expand transition using max-height to accommodate varying content sizes, I am facing difficulties with transitioning t ...

Combining HTML/CSS to overlay text on an image - EMAIL

Why does Google keep stripping my <style> tag when I try to overlay text on an image? I want the image to be on the left with two text blocks positioned over it on the right (one higher and one lower). It looks fine visually, but when I send it to m ...

List layout enhancement provided by Bootstrap

I'm facing an issue with the layout of a feature list content box. While it looks good on desktop, there are problems in smaller versions like tablet and mobile devices. The four words with icons are breaking and I believe this might not be the best s ...

What is the best way to add rounded corners to tables in Bootstrap 3?

Is there a way to give the top and bottom corners of a table rounded edges? I am currently using Bootstrap 3 tables, but they have no corner radius by default. How can I achieve this effect? ...

One problem with placing Bootstrap columns inside another column

Currently, I am in the process of working on a website that requires a description section. To achieve this, I decided to use two Bootstrap columns – one with a size of 8 and another with a size of 4, totaling up to 12 grid units. Inside the column sized ...

The problem arises from misinterpreting MIME types when serving SVG files, causing the resource to be seen as an image but transferred with

Having some issues targeting SVG images with CSS to use as backgrounds on certain elements. When I try to access the image directly here, it works perfectly fine. However, when using it in CSS, I encounter the following error: Resource interpreted as Imag ...