Place the <span> element at the bottom of the <ul> list

Struggling to align the captions of an image carousel at the bottom of the <ul>. No matter what I try, it just doesn't look right.

Check out my Fiddle here

Below is the HTML structure:

<div class="carousel">
    <ul>
        <li>
            <img src="someImage.jpg">
            <span class="caption">Some Caption</span>
        </li>
        <li>
            <img src="someImage.jpg">
            <span class="caption">Some Caption</span>
        </li>
    </ul>
</div>

This is my CSS styling:

.carousel img {
    max-height: 200px;
    max-width: 200px;
    vertical-align: middle;
}
.carousel li {
    display: inline-block;
    padding: 5px;
    position: relative;
    cursor: pointer;
    width: 200px;
    height: 200px;
    text-align: center;
    -webkit-transition: all 0.1s cubic-bezier(.91, .8, 0, 1);
    -moz-transition: all 0.1s cubic-bezier(.91, .8, 0, 1);
    -ms-transition: all 0.1s cubic-bezier(.91, .8, 0, 1);
    -o-transition: all 0.1s cubic-bezier(.91, .8, 0, 1);
    transition: all 0.1s cubic-bezier(.91, .8, 0, 1);
}
.carousel .caption {
    display: block;
    position: absolute;
    bottom: 10px;
    text-align: center;
    background-color: rgba(240,240,240,0.75);
    font-weight: bold;
    font-size: 12px;
    padding: 5px 0 5px 0;
    width: 200px;
    max-width: 200px;
}

Answer №1

If you desire your images to be perfectly centered within their containers, one solution is to wrap the image with a div element so that it fits nicely inside the li element.

//Markup
<div><img src="https://www.metsales.com/MetropolitanSales/ConstantContact/Bematech/images/br200bt.png" /></div>
//css
.carousel li img {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

CSS now offers transformations which can elegantly center align elements both vertically and horizontally, making styling more attractive than ever.

Check out this Fun Fiddle (may or may not be fun)

Answer №2

Here is some suggested CSS code to try:

.carousel li {
    display: block;
    padding: 5px;
    position: relative;
    cursor: pointer;
    width: 200px;
    height: 200px;
    text-align: center;
    -webkit-transition: all 0.1s cubic-bezier(.91, .8, 0, 1);
    -moz-transition: all 0.1s cubic-bezier(.91, .8, 0, 1);
    -ms-transition: all 0.1s cubic-bezier(.91, .8, 0, 1);
    -o-transition: all 0.1s cubic-bezier(.91, .8, 0, 1);
    transition: all 0.1s cubic-bezier(.91, .8, 0, 1);
    float:left;

}

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

When scrolling, dynamically change the background color by adding a class

I am looking to achieve a scroll effect where the color of the menu buttons changes. Perhaps by adding a class when scrolling and hitting the element? Each menu button and corresponding div has a unique ID. Can anyone suggest what JavaScript code I should ...

Having trouble with jQuery UI draggable when using jQueryUI version 1.12.1?

Currently, I am diving into the world of jQuery UI. However, I am facing an issue with dragging the boxes that I have created using a combination of HTML and CSS. My setup includes HTML5 and CSS3 alongside jQuery version 1.12.1. Any suggestions or help wou ...

``Incorporate images into a slideshow container with proper alignment

I'm currently using a jquery slideshow on my homepage with fading images, but I'm having trouble centering them. The images are all different sizes and they're aligning to the left instead of being centered. Here is the CSS code I've b ...

Tips on making a fresh form appear during the registration process

After clicking on a submit button labeled as "continue" within a form, a new form will appear for you to complete in order to continue the registration process. ...

When attempting to check and uncheck checkboxes with a specific class, the process fails after the first uncheck

I have a set of checkboxes and one is designated as "all." When this box is clicked, I want to automatically select all the other checkboxes in the same group. If the "all" box is clicked again, I would like to deselect all the other checkboxes. Currently ...

When attempting to read text from an HTML file, JTextPane fails to include a newline character in the output

I am currently working on a project that involves extracting text from an HTML file based on the element's id and displaying it in a JTextPane. However, I am facing an issue where the displayed text does not go to a new line. Here is a snippet of the ...

A method designed to accept an acronym as an argument and output the corresponding full name text

Having trouble with my current task - I've got an HTML file and external JS file, and I need a function that takes an element from the 'cities' array as input and returns a string to be used in populating a table. I've set up a functio ...

Attempting to create a footer design featuring buttons aligned to the left and right sides

I am trying to create a layout similar to the bottom of Google's homepage using this code. However, no matter what I try, the "lists" are still appearing vertically instead of horizontally. My goal is to have three columns of links positioned side by ...

Is there an issue with this website link?

What is causing the Xul app to display the error message: XML Parsing Error: not well-formed when encountering this code snippet: <browser class="AppBar" type="content" src="test.html?img1=img1.jpg&img2=img2.jpg" flex="4"/> specifically ...

Ways to enlarge the diameter of the inner circle

I've implemented some CSS with JQuery, as seen in this JSFiddle. However, I'm having trouble increasing the width and height of the green circle to be slightly larger than the gray circle (referred to as the main circle) which is positioned at a ...

There is a space above the second div when using display inline-block

I'm encountering an issue with the display inline block property. I have two divs that I want to position next to each other, but there's a strange gap above the second div (#store_header_text) that I can't seem to explain. I've tried r ...

Determine the maximum size of a specified number of square divs that can fit within responsive parent divs

I am working on creating a grid of square divs inside a container with variable height and width. The number of square div's is predetermined. All square divs will have images with the same dimensions (similar to the example). They should align left ...

A white background emerges when I select md-dropdown

Lately, I've been experiencing an issue on my website where a white background pops up whenever I click on a dropdown (md-select) in my form. Initially, it only happened with forms inside a modal, but now it's affecting dropdowns across the entir ...

What's the best way to refresh append() functionality within a modal? I'm currently working with NODE JS and AJAX and

Whenever I click the modal, the append() calls are adding HTML content. But if I try to use empty() or html(), the modal stops appearing altogether. What is the correct approach to creating this modal? function loadModalContent(id) { $('#myModal& ...

Using the / (forward slash) in CSS styling statements

Similar Query: Understanding the CSS font shorthand syntax As I was examining the styling on Apple's website, I encountered a CSS rule that left me puzzled: body { font: 12px/18px "Lucida Grande","Lucida Sans Unicode",Helvetica,Arial,Verdana, ...

css side by side with immovable element

Seeking assistance with CSS. I am looking to create a layout as follows: I want a center-fixed menu with a width of 960px - this part is straightforward. Alongside the menu, I aim to have two divs: one spanning from the left edge of the screen to the cl ...

Slide-out left menu using HTML and CSS

Currently, I am in the process of constructing a website that requires a menu to gracefully slide from the left side of the screen (with a width of 0px) to the right side (expanding to a width of 250px), all with the help of jQuery animations. Here is wha ...

Uniquely tag an uploaded file

My code for uploading files is as follows: var xhr = new XMLHttpRequest(); xhr.upload.addEventListener("progress", uploadProgress, false); xhr.open("POST", requestUrl, true); xhr.send(f); I want to draw your attention to the fact that I have attached a l ...

Discover the step-by-step guide for inserting personalized HTML into the current widget screen on Odoo 12 with

For the past 3 days, I've been stuck trying to figure out how to print order items. My goal is to have a custom HTML code added to a div with the class 'order-print' when the Order button is clicked. I am using odoo 12 and facing issues wit ...

Create a soft focus on the background sans any filters

I am in the process of developing a website and have implemented code to blur out the background: CSS #background{ background: url(img/bg.jpg) no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o ...