"Placing an image at the bottom within a DIV container in HTML

My goal is to neatly align a group of images at the bottom of a fixed-height div. The images all have the same height and width, making the alignment easier.

Here is the current structure of my code:

<div id="randomContainer">
    <div id="imageContainer">
        <img src="1.png" alt=""/>
        <img src="2.png" alt=""/>
        <img src="3.png" alt=""/>
        <img src="4.png" alt=""/>
    </div>
    <div id="navigationContainer">
        <!-- navigation stuff -->
    </div>
</div>

In my CSS, I have set the following:

div#imageContainer {
    height: 160px;  
    vertical-align: bottom;
    display: table-cell;
}

So far, I have successfully aligned the images at the bottom using display: table-cell along with vertical-align: bottom.

However, I am wondering if there is a more efficient way to accomplish this without using display: table-cell. Any suggestions for cleaner code?

Answer №1

To achieve the desired layout, configure the parent div with the attribute position:relative and the child element with position:absolute; bottom:0

Answer №2

Your code can be found at this link: http://jsfiddle.net/WSFnX/

While using display: table-cell is a good choice, please keep in mind that it may not work in IE6/7. Otherwise, it's a safe option. You can read more about it here: Is there a disadvantage of using `display:table-cell`on divs?

To resolve the space at the bottom, simply add vertical-align: bottom to the actual img elements:

You can view the updated code with this link: http://jsfiddle.net/WSFnX/1/

If you want to remove the space between images, check out this discussion: bikeshedding CSS3 property alternative?

Here's a demonstration showcasing how to remove whitespace in your HTML: http://jsfiddle.net/WSFnX/4/

Answer №3

To achieve this layout, you can utilize the align-items: flex-end; property along with either display: flex; or display: inline-flex;

div#imageContainer {
    height: 160px;  
    align-items: flex-end;
    display: flex;

    /* If not set elsewhere, you do not need to explicitly define the value of flex-direction since it defaults to row */
    /*flex-direction: row;*/
}

Check out this JSFiddle example

For a comprehensive guide on flexboxes, visit CSS-Tricks

Answer №4

<section> with specific dimensions

section {
  position: absolute;
  width: 50%;
  height: 75%;
}

<figure>'s styled individually

figure {
  position: relative;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  width: auto; /* maintaining aspect ratio */
  height: auto; /* maintaining aspect ratio */
  max-width: 100%; /* fits within section boundaries */
  max-height: 100%; /* fits within section boundaries */
  margin: auto auto 0; /* centered at the bottom */
}

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

Unable to retrieve DOM value due to Vue.js template being inaccessible in Chromium, including from both DevTools and extensions

Currently, I’m developing a Chrome extension that needs to retrieve specific values from a webpage such as the item title. However, instead of fetching the actual title, it is reading a Vue.js template variable. Even when I use DevTools to inspect the p ...

Error: The function execute_script() is expecting between one and two arguments, however three arguments were provided

While attempting to utilize the Selenium method execute_script() in an automated UI test script, I encountered a type error. The error message indicates that there are too many arguments being passed. TypeError: execute_script() takes from 1 to 2 positiona ...

Tips for aligning and emphasizing HTML content with audio stimuli

I am looking to add a unique feature where the text highlights as audio plays on a website. Similar to what we see on television, I would like the text to continue highlighting as the audio progresses. Could someone please provide me with guidance on how ...

How come the buttons in the navbar are not aligning to the right with justify-content-end?

Having trouble aligning the two buttons in my bootstrap navbar to the right. Despite using justify-content-end, it doesn't seem to work. I thought applying d-flex to the container and then justify-content-end to the items would solve the issue, but e ...

The entire image is unable to be shown within the div

When adding images to a carousel, I encountered an issue where only the top half of the image is displayed on the page. It seems that the image is not adjusting itself to fit the div container properly, resulting in only a portion of it being visible behin ...

Is there a way to update CSS dynamically in server-side ASP.NET?

Is there a way to dynamically change the CSS values based on the server's response? I attempted to use inline expressions, but unfortunately, it did not yield the desired outcome. @keyframes loading-1 { 0% { -webkit-transform: rotate(<%=cpuRigh ...

Initiate an "execute.document" command directly from the address bar

While reviewing my old website, I stumbled upon this snippet: <input type="image" id="QuickPass" name="QuickPass" src="/images/QuickPass.gif" alt="Quick Pass" onclick="document.pressed=this.value" value="QuickPass" /> nestled within this form: & ...

Showing a div above another div without relying on z-index

I have designed custom drop down menus that consist of one <div> containing the current value and functioning as a <select> field, with another <div> below it that appears when the top one is clicked, displaying all the <option> val ...

The Table and Div elements do not have identical widths when set to 100%

I am facing an issue with a Div and Table placed inside a container. Although they are meant to completely fill the container, occasionally there is a one pixel difference which can be quite annoying. I have prepared a test case and attached a screenshot h ...

Decrease the dimensions of the image while maintaining its width at 100%

I've got a dilemma with the images on my website that are linked from image hosting sites. They all need to be displayed at 100% width, but some of them have huge pixel dimensions which cause slow loading times. Is there a way to resize the images wi ...

Steps to connect my CSS with my HTML in a website hosted on GitHub

I am experiencing an issue with my website hosted on Github pages. It seems to be unable to read the CSS file that I have linked to it. Here is a snippet of my HTML code: <!DOCTYPE html> <link rel="stylesheet" type="text/css" href="https://githu ...

preventing elements from moving unexpectedly as the navigation bar becomes fixed at the top of the page

I have a website that features a Bootstrap 3 navbar. This navbar is positioned 280px below a block div and becomes sticky at the top of the page when scrolled to that point. HTML (within < head > tags) <script> $(document).ready(function() ...

The Bootstrap nav-tab functions perfectly on a local server, but unfortunately does not work when hosted remotely

UPDATE: Issue resolved so I have removed the Github link. It turns out that Github pages require a secure https connection for all linked scripts. Always remember to check the console! I encountered an unusual bug where the Bootstrap nav-tab functionality ...

What are the steps to update your profile picture using Angular?

In my Angular 6 application, I am implementing an image upload feature with the following code: Html: <img [src]="url ? url : 'https://www.w3schools.com/howto/img_avatar.png'"> <br/> <input type='file' (change)="onSelec ...

Exploring the Concept of Nested ViewModels in Knockout.js Version 3.2.0

I have a global view model that is applied to the main div and I also have other view models that I want to apply to nested elements within my main div However, I am encountering an issue: You cannot bind multiple times to the same element. Below is ...

Selecting options from the Gmail dropdown menu

I'm attempting to create a dropdown menu similar to the one in Gmail using Bootstrap. However, I have encountered 2 issues: 1- I am unable to click on the input checkbox to select all 2 - I would like it so that if I select all, the input gets sele ...

What steps are necessary to facilitate payments through Stripe instead of directly on my Wordpress website?

On my Wordpress website, I have created a page where users can select a subscription offer. Currently, the layout looks like this: https://i.sstatic.net/qltbU.png My goal is to redirect users to a Stripe payment page when they click on any of the subscrib ...

Displaying images stored in Laravel backend using Angular frontend

I am facing a challenge where I need to display an image on the frontend using Angular, but the image is stored on the backend in Laravel 5.5. I have already attempted some solutions, but they have not worked. What should I do? Below is the error message ...

CSS media queries to exclude a property for mobile devices

I have a CSS class with the width property set to calc(100% - 17px). However, I want to ignore this property completely for devices with specific resolutions. I've tried using media queries and values like initial, inherit, and unset for the width pro ...

Using Javascript to display or conceal a specific child element within a loop, based on which parent element has been clicked

I need assistance with creating a grid of projects where clicking on a specific 'project' in the loop will display the corresponding 'project_expanded' div, while hiding all other 'project_expanded' divs. My initial plan was ...