Is it possible to vertically and flexibly center a <div> over an <img>?

Check out this HTML:

<div class="float">
    <img class="left" src="bradBeachHeart.JPG" alt="Brad at the Lake" />
    <img class="left" src="mariaNavi.jpg" alt="Making Maria Na'vi" />
    <img class="left" src="mattWaterRun.jpg" alt="Photoshopped Matt" />
</div>

This content is styled to align on the side of the page using the following CSS rules:

div.float
{
    border-right: 1px solid orange;
    position: absolute;
    z-index: 2;
    margin-left: 5px;
    margin-top: 5px;
    float: left;
    width: 200px;
}

div.mask
{
    position: relative;
    z-index: 1;
    margin-top: 5px;
    float: left;
    width: 206px;
    height: 805px;
    background-color: white;
}

img.left
{
    z-index: inherit;
    margin-bottom: 3px;
    float: left;
    width: 200px; 
    min-height: 200px; /* for modern browsers */
    height: auto !important; /* for modern browsers */
    height: 200px; /* for IE5.x and IE6 */
    opacity: 0.4;
    filter: alpha(opacity=40);
}

img.left:hover
{
    opacity: 1;
}

The column of images displayed includes album covers, but there's a need to add album titles to each cover. These titles should appear inside an orange rectangle with white text, vertically centered over the image. The challenge lies in aligning these titles correctly based on the varying heights of each image.

In addition to the main styling, there is a gradient effect that causes the top of the first image to fade into white and the bottom of the last image to fade into white. Hovering over the gradient triggers a scrolling feature using jquery. However, maintaining these gradients' fixed locations and cutting off image edges when resizing the page is proving difficult.

Another requirement is to set the album title at 90% opacity and the image at 40% opacity. When hovering over the image or title, they should both transition to 100% and 30% opacity respectively, creating a smooth visual effect. Resolving this opacity change during hover states presents another challenge.

Answer №1

To easily center titles dynamically, consider using jQuery for the first part.

Check out this example: http://jsfiddle.net/p7GzB/6/

If you prefer not to use jQuery, another option is to utilize container divs and a cross-browser solution to achieve vertically centered titles.

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 output value in console using eventListener

Hey everyone, I'm new to JavaScript and trying to deepen my understanding of it. Currently, I am working on an 8 ball project where I want to display the prediction in the console. However, I keep getting an 'undefined' message. const predi ...

What is the best way to adjust the layout of these two elements using CSS in order to display them on

I need assistance with adjusting the layout of a dropdown list next to its label in an Angular html page. <div *ngIf="this.userRole == 'myrequests'" class="col-2" [ngClass]="{ 'd-none': view != 'list&apo ...

Tips for accessing the value stored within the parent element

As someone who is new to the world of javascript and typescript, I am currently working on an ionic application that involves fetching a list of values from a database. These values are then stored in an array, which is used to dynamically create ion-items ...

Techniques for incorporating a variable into the value field in JavaScript

let y = data[1]; cell1.innerHTML ='<input id="text" type="text" value= "'y'"/>' ; This snippet of code does not render any content when attempting to pass the variable, but if you provide a specific value like "h", it will displa ...

Modifying the appearance of Bootstrap 4 Nav-tabs using CSS

I have implemented Bootstrap 4 Nav-tabs as shown below: <ul class="nav nav-tabs" id="myTab" role="tablist"> <li class="nav-item"> <a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" ...

The uppermost part is malfunctioning

Below is the snippet of code: $('> li', this).each(function (index) { var top_space = $(this).css('padding-top'); $(this).prepend('<div></div>'); $('> div', this).css({ position ...

"Learn how to easily format specific characters in JavaScript using the text plugin to create bold text strings with a unique

I would like to transform this text into something like "|| something 1 || something 2 || more || last one ||" and then make all of that string bold by adding "|" around it then it would look like this "|| something 1 || something 2 || more || last one | ...

Automatically selecting a div using jQuery upon loading the page

Hello everyone. I've implemented some jQuery code that allows div elements to slide horizontally when a link is clicked. However, upon page load, no link is clicked and therefore no div is visible (only the ul is visible). I would like to have the div ...

DOM not rendering Angular function output successfully

I recently delved into learning Angular and encountered a strange issue. Whenever I try to pull data using {{some.data.goes.here}} in the HTML, the result does not show up in the DOM. (function() { var app = angular.module('app', []); app. ...

Including new styles in CKEDITOR.stylesSet that pertain to multiple elements

My idea involves creating a unique bullet list style with two specific features: a. A blue arrow image replacing the standard list icon b. Very subtle dotted borders above and below each list item. I am looking to incorporate this design into CKEditor t ...

Troubleshooting border-radius problem with Firefox-CSS for the pseudo-element "before"

I'm encountering an issue with a card-element in bootstrap-4 that has a front and back side. When hovered over, the back side is displayed. To achieve a "folded corner effect," I'm using a pseudo-element(:before) on the front of the card. This me ...

Use the on-screen keyboard to move around by using the arrow keys and choose a value from the list to

I am currently working on developing an on-screen keyboard that allows for navigation using arrow keys and selection with the enter key. My goal is to have each selected key append to an input field. Below is the HTML code I have implemented: <div id ...

Issue with arranging blocks in a horizontal line in Opera

I am currently experiencing an issue with a wide page that contains an information block and numerous images positioned to the right. The layout is designed to be used with a horizontal scrollbar. While this setup works perfectly in Firefox, Safari, Chrom ...

When a div element is clicked, it becomes the selected element and borders are displayed around it

Within a div on my wordpress site, the logo is prominently displayed. Feel free to check it out here: Strange issue - whenever I click on the logo, a large rectangular box suddenly appears. I've experimented with the outline and user-select properti ...

Modify the directory attribute based on a constantly changing variable

I need to adjust the dir attribute based on a variable that changes dynamically. <input [id]="'element'+i" [(ngModel)]="parent.firstName" class="form-control input-lg" ...

Tips for aligning two TD elements with varying lengths in the same row:- Consider setting a specific width for each

Can anyone assist me in properly aligning this structure? I am looking to reduce the height of the "Todays Special" td significantly. The size of this td expands based on the content, for example, if new fruits are added. Any help in resolving this would ...

Updating the font style in MUI with React 18

I attempted to create a new theme in order to replace the default font family of MUI but unfortunately, it was not successful. This is what my theme component looks like: import { createTheme } from "@mui/material/styles"; const theme = createT ...

"I recently started using Protractor and as per company policy, I am unable to utilize XPath. I am facing difficulties with the code below and would greatly appreciate any insights or assistance provided

I am looking for guidance on how to write automation test scripts for a small AngularJs application using the cucumber-protractor-typescript framework. As someone new to Angular applications, I am particularly concerned about creating reliable locators. B ...

CSS shimmer effect does not smoothly transition between borders

Currently, I'm diving into a tutorial on YouTube that teaches how to craft a CSS Glowing Border Animation After putting in the effort to replicate the animation, I noticed a glitch that's been bothering me. It seems like there's an abrupt s ...

The Bootstrap modal fails to open

I am currently working on implementing a Navbar button that triggers a Bootstrap modal containing a form. While looking for resources, I stumbled upon a useful script at https://gist.github.com/havvg/3226804. I'm in the process of customizing it to su ...