Aligning images vertically within floated elements

I'm struggling to vertically align some images to the bottom within floated elements, and I just can't seem to make it work.

Check out this JSFiddle example. You'll notice that the images are currently aligned to the top.

http://jsfiddle.net/decr9gfj/1/

Here is a snippet of the code in question:

<ul class="clearfix">
    <li><a href="#"><img src="http://fpoimg.com/100x150"></a></li>
    <li><a href="#"><img src="http://fpoimg.com/100x100"></a></li>
    <li><a href="#"><img src="http://fpoimg.com/100x75"></a></li>
</ul>

 

ul {
    list-style-type:none;
    margin:0;
    padding:0;
    background:#eee;
    display: block;
    vertical-align:bottom;
}

li {
    float:left;
    padding:0px 5px;
}

a {
    display:block;
}

img {
    display:block;
    vertical-align:bottom;
}

Answer №1

Update the styling of the list items by removing the float property and adding display:inline-block instead.

li {
    display:inline-block;
    padding:0px 5px;
}

Check out the example on jsFiddle

ul {
    list-style-type:none;
    margin:0;
    padding:0;
    background:#eee;
    display: block;
    vertical-align:bottom;
}
li {
    display:inline-block;
    padding:0px 5px;
}
a {
    display:block;
}
img {
    display:block;
    vertical-align:bottom;
}
.clearfix:after {
    visibility: hidden;
    display: block;
    font-size: 0;
    content:" ";
    clear: both;
    height: 0;
}
.clearfix {
    display: inline-block;
}
/* start commented backslash hack \*/
 * html .clearfix {
    height: 1%;
}
.clearfix {
    display: block;
}
/* close commented backslash hack */
<ul class="clearfix">
    <li><a href="#"><img src="http://fpoimg.com/100x150"></a>

    </li>
    <li><a href="#"><img src="http://fpoimg.com/100x100"></a>

    </li>
    <li><a href="#"><img src="http://fpoimg.com/100x75"></a>

    </li>
</ul>

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

Delete the span element if the password requirements are satisfied

I am implementing password rules using span elements. I aim to dynamically remove each span that displays a rule once the input conditions are met. Currently, I have succeeded in removing the span related to the minimum length requirement but I am unsure h ...

Apply a background image to the input[type='submit'] along with text

<input name="submit" type="submit" value="Search" class="button search"> Is it feasible to incorporate a CSS gradient using background-image: and still display the text within the value attribute? Whenever I introduce a background-image, it conceal ...

How to display an image in a pop-up with a title

I am currently using the Bootstrap framework and I am trying to create a popup image with a title, but it only shows the image. I am not sure how to add code in JavaScript to display the title as well. Can someone please assist me? Here is my code: Javas ...

What causes the disparity in functionality between simple html and css in an Angular 2 project compared to a vanilla html website?

When incorporating the following html/css into a new Angular project created with Angular CLI using 'ng new ProjectName', I encountered issues. Despite adding the CSS to app.component.css or styles.css and the HTML to app.component.html, the Angu ...

Children of flex items sharing the same height

I'm struggling with creating a flexbox responsive grid and need some guidance. My goal is to make all the .block divs have equal height, with the .bottom div positioned at the bottom. The current solution achieves this, but when the h2 heading spans ...

Is there a way to access other HTML pages in a separate folder from the index file when running npm start?

At the moment, I have a simple index.html file and would like to access the app.html file located in a subfolder from the index.html. You can see the folder structure here: https://i.sstatic.net/IGcOk.png My app.html file is inside the 'app' sub ...

Rearrange the position of the divs in every other container

Assume that I have the following HTML structure: <div class="article"> <div class="article_img"></div> <div class="article_preview"></div> </div> Both article_img and article_preview elements have a defined width and ...

The accordion won't function properly if it is added using append() after the document is ready

I have implemented a button to add an accordion, but unfortunately it doesn't seem to be working properly. I am unsure of how to troubleshoot and resolve this issue. If the accordion HTML is appended after the document.ready() function, then the accor ...

Invoke JavaScript when the close button 'X' on the JQuery popup is clicked

I am implementing a Jquery pop up in my code: <script type="text/javascript"> function showAccessDialog() { var modal_dialog = $("#modal_dialog"); modal_dialog.dialog ( { title: "Access Lev ...

Does the Parent Tag style override the child tag style when hovering?

I am currently dealing with some style issues. How can I apply the styling of the parent tag to the child tag when hovering over it? Let's illustrate this with a simple example. .outer:hover { background: yellow; z-index: 1; position: relativ ...

Top method for triggering an external JavaScript function through an HTML element's onclick event obtained from an Ajax request

index.php: <html> <head> <script type="text/javascript" src="script.js"></script> </head> <body> <div id="box"></div> <div onclick="getContent()">Open Window</div ...

Executing a script on a different HTML page without the need to reload it

I'm currently working on incorporating a notification system inspired by Facebook's design. This system will feature an icon in the header that, when clicked, reveals a drop-down containing a table of sorted notifications for the user. My goal is ...

When the canvas is in full screen mode, my div elements are hidden

Currently, I am immersed in a 360-panorama project, utilizing panolens.js and three.js. While Panolens offers fullscreen mode functionality, the problem arises when entering this mode as the canvas conceals all of my div elements. One particular div elemen ...

The onClick event for "history.go(0)" is functional in Internet Explorer, but it does not work in Mozilla Firefox. What can be done to address this problem specifically for Mozilla browser?

After experimenting with different browser compatibility, I have discovered a way to clear all fields when clicking the "New" button. By using the code onClick="history.go(0)", the fields are successfully emptied in IE but unfortunately fail in Mozilla. ...

Problem with ineffective responsive CSS on mobile devices

Is there anyone who can assist me with this issue? I have set up a CSS grid that works properly above 768px when the min-width is specified. However, as I scale below that threshold, the layout remains unchanged and the media tag doesn't seem to take ...

Leveraging both onmouseover and onmouseout for container expansion

My goal is to utilize JavaScript along with the HTML events "onmouseover" and "onmouseout" to create a dynamic container. Essentially, I want the container to act as simply a heading when the mouse is not hovering over it, but expand to display additional ...

Enhance the appearance of Google Maps by incorporating gradient effects, box shadows, or other similar visual

How can I add a linear gradient to Google Maps? Below is my code snippet. HTML <div id="map"></div> CSS #map{ height:100vh; background: linear-gradient(90deg, #f7f8fa 0%, rgba(247, 248, 250, 0) 18.73%), linear-gradient(180deg, # ...

Displaying a specific item in react js with the help of bootstrap version 5.0

I am currently working with Bootstrap v5.0 and facing an issue with displaying the selected item from a drop-down menu. Ideally, when I click on "Action," it should show "Action" instead of the default "Dropdown Link" text. Can anyone provide guidance on ...

Collapsing borders in JavaFX 8

Hey there! I'm having a little issue with JavaFX 8 components. I'm trying to make them sit next to each other with borders, but it's not quite working out. Is there a way to make them blend together and share one border? import javafx.geome ...

React Icons and Browser Tab Alerts

Is there a way to incorporate notifications into my website's favicon when the browser tab is not in focus? My tech stack includes React, Material UI, and TypeScript. I assume this is a frequent requirement, yet I haven't come across a simple so ...