Text remains constant until the mouse hovers over the image

Check out this Example

Here is the HTML code:

<ul class="img-list">
    <li>
        <img src="http://s11.postimg.org/ynw9rnexf/Cetina_river.jpg" width="360px" height="280px" />
<span class="text-content"><span>
 Text To Display</span></span>
    </li>
</ul>

This is the CSS used:

ul.img-list {
     list-style-type: none;
     margin: 0;
     padding: 0;
     text-align: center;
 }
 ul.img-list {
     display: inline-block;
     height: 150px;
     margin: 0 5px 1em 0;
     position: relative;
     width: 360px;
     margin-top:-5px;
 }
 span.text-content {
     background: rgba(0, 0, 0, 0.5);
     color: white;
     cursor: pointer;
     display: table;
     height: 150px;
     left: 0;
     position: absolute;
     top: 0;
     width: 150px;
 }
 span.text-content span {
     display: table-cell;
     text-align: center;
     vertical-align: middle;
 }
 span.text-content {
     background: rgba(0, 0, 0, 0.5);
     color: white;
     cursor: pointer;
     display: table;
     height: 150px;
     left: 0;
     position: absolute;
     top: 0;
     width: 150px;
     opacity: 0;
 }
 ul.img-list li:hover span.text-content {
     opacity: 1;
 }
 span.text-content {
     background: rgba(0, 0, 0, 0.5);
     color: white;
     cursor: pointer;
     display: table;
     height: 280px;
     left: 0;
     position: absolute;
     top: 0;
     width: 360px;
     opacity: 0;
     -webkit-transition: opacity 500ms;
     -moz-transition: opacity 500ms;
     -o-transition: opacity 500ms;
     transition: opacity 500ms;
     font-family: Droid Arabic Kufi;
     font-size: xx-large;
 }

When hovering over the image, a text is displayed above it. I want the text to be fixed at the bottom of the image and move to the top when hovered over.

I want the last 50px of the image to have a black background with the text constantly visible, and to switch to the same functionality on hover.

Your advice on achieving this would be greatly appreciated.

Answer №1

Initially, there seems to be a repetitive definition of span.text-content.

Furthermore, I have made alterations to your CSS. Feel free to review the changes on this fiddle http://jsfiddle.net/ynrsh3ue/2/

 ul.img-list
 {
    list-style-type: none;
    margin: 0;
    padding: 0;
    text-align: center;
    display: inline-block;
    height: 150px;
    margin: 0 5px 1em 0;
    position: relative;
    width: 360px;
    margin-top:-5px;

}

span.text-content span
{
    display: table-cell;
    text-align: center;
    vertical-align: bottom;
    -webkit-transition: all 500ms;
    -moz-transition: all 500ms;
    -o-transition: all 500ms;
    transition: all 500ms;
}


ul.img-list li:hover span.text-content
{
    opacity: 1;
    background: rgba(0,0,0,0.5);
    height:280px;
    top:0px;
}

ul.img-list li:hover span.text-content span
{
    vertical-align:middle;
}
span.text-content
{
    background: rgba(0,0,0,1);
    color: white;
    cursor: pointer;
    display: table;
    height: 50px;
    left: 0;
    position: absolute;
    top: 230px;
    width: 360px;
    opacity: 1;
    -webkit-transition: all 500ms;
    -moz-transition: all 500ms;
    -o-transition: all 500ms;
    transition: all 500ms;
    font-family: Droid Arabic Kufi;
    font-size: xx-large;
}

Answer №2

Did you intend to create something like this? Fiddle

* {
  margin: 0;
  padding: 0;
  border-spacing: 0;
  top: 0;
}
ul.img-list {
  list-style-type: none;
  text-align: center;
}
ul.img-list {
  border-spacing: 0;
  display: inline-block;
  height: 150px;
  position: relative;
  width: 360px;
}
span.text-content span {
  display: table-cell;
  text-align: center;
  vertical-align: middle;
}
ul.img-list li:hover span.text-content {
  opacity: 1;
  background: rgba(0, 0, 0, 0.5);
  margin-top: -280px;
  height: 280px;
  -webkit-transition: 500ms;
  -moz-transition: 500ms;
  -o-transition: 500ms;
  transition: 500ms;
}
span.text-content {
  background: black;
  position: relative;
  color: white;
  cursor: pointer;
  display: table;
  height: 50px;
  left: 0;
  top: -5px;
  width: 360px;
  opacity: 1;
  -webkit-transition: 500ms;
  -moz-transition: 500ms;
  -o-transition: 500ms;
  transition: 500ms;
  font-family: Droid Arabic Kufi;
  font-size: xx-large;
  z-index: 2;
}
<ul class="img-list">
  <li>
    <img src="http://s11.postimg.org/ynw9rnexf/Cetina_river.jpg" width="360px" height="280px" /> <span class="text-content">
            <span>Text To Display</span>
    </span>
  </li>
</ul>

Answer №3

Check out the updated JSFiddle I made for you: http://jsfiddle.net/chimos/ynrsh3ue/1/

To achieve the desired outcome, make sure to modify and remove certain CSS rules as follows:

 ul.img-list {
     list-style-type: none;
     margin: 0;
     padding: 0;
     height: 100%;
     text-align: center;
 }
 ul.img-list {
     display: inline-block;
     height: 150px;
     margin: 0 5px 1em 0;
     position: relative;
     width: 360px;
     margin-top:-5px;
 }
 ul.img-list li {
     position: relative;
 }
 span.text-content span {
     display: table-cell;
     text-align: center;
     vertical-align: middle;
 }
 ul.img-list li:hover span.text-content {
     height: 280px;
     /*opacity: 1;*/
 }
 span.text-content {
     background: rgba(0, 0, 0, 0.5);
     z-index: 999;
     color: white;
     cursor: pointer;
     display: table;
     height: 20px;
     left: 0;
     position: absolute;
     bottom: 0;
     width: 360px;
     /*opacity: 0;*/
     -webkit-transition: height 500ms;
     -moz-transition: height 500ms;
     -o-transition: height 500ms;
     transition: height 500ms;
     font-family: Droid Arabic Kufi;
     font-size: xx-large;
 }

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

Enhance the appearance of your Dojo TabContainer when viewing in Internet Explorer

Firefox seems to handle the following code without any issues: < div style="position:absolute;top:0px;margin-top:60px;bottom:0px;width:100%"> < div id="mainTabContainer" dojoType="dijit.layout.TabContainer" style="width:100%;height:100%"> {% for row ...

What criteria do browsers follow to determine the specific colors to use for border styles like inset and outset?

When I set border: 1px outset blue; as the style for an element, the browser displays two distinct border colors: one for the top and left borders, and another for the bottom and right borders. li { border: 10px outset #0000FF; color: #FFF; ...

As soon as I insert an image, the text on the right automatically moves to the bottom

I'm going crazy over this issue. My navigation bar has three div elements, each with text aligned both vertically and horizontally at the center. However, when I insert an image (an SVG icon of a zoom lens) before the "search" text, it shifts the tex ...

Move your cursor over an image to reveal another image on top without impacting the image underneath by using background-image

Is there a way to create an effect where hovering over a specific book image will display a checkmark, indicating selection upon click? Ideally, users should be able to press alt (cmd on mac) to select multiple books simultaneously. Check out the HTML bel ...

Determining Text Color Based on Background Hue

Is it possible to create a div that dynamically changes text color based on the background color surrounding it? I want the text to switch between two different colors, with the font color being the opposite of the background color. For example, black text ...

What is causing the bullets for the unordered list to appear before the items are inserted into the list?

Can you explain why the bullets are showing up before the list items are added? <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>To Do List</title> </head> <body> ...

Tips for adjusting the maximum width and content-based width for columns within an HTML/CSS table

I'm working on a simple HTML/CSS code featuring a container with two adjustable slots, controlled by a handler in the middle to modify the space each slot occupies. The first slot contains a table with fixed columns, automatic columns, and limited col ...

How can I position 7 images absolutely within a specific div?

I've been working on a website where users can have their avatars displayed using a JS function that loads 7 different images onto the page. These images correspond to different elements such as skin base, hair, eyes, mouth, shirt, shoes, and pants, a ...

"Getting Started with Respond.js: A Step-by-Step

I've been struggling to find clear instructions on how to properly set up respond.js. Should I just unzip it into the htdocs folder, or do I only need respond.min.js in there? Then, do I simply reference the file like this... <script src="respon ...

Generate a custom map by utilizing JavaScript and HTML with data sourced from a database

Looking for guidance on creating a process map similar to this one using javascript, html, or java with data from a database. Any tips or suggestions would be appreciated. Thank you in advance. ...

The accuracy of IE9 <section> is not quite up to par

When viewing This Page in IE9, the element section#tcs-website-content appears as 990px wide even though its CSS property is set to width: 100%. This occurs despite all parent elements also having a width of 100%, resulting in a browser width of 1024px. A ...

Tips on creating a horizontal scrolling effect using the mouse

Is there a way to enable horizontal scrolling by holding down the mouse click, instead of relying on the horizontal scroll bar? And if possible, can the scroll bar be hidden? In essence, I am looking to replicate the functionality of the horizontal scroll ...

Show only a cropped section of a resized image within a div

I have a script that calculates the best region of an image to display within a specific div size. This calculation is done in PHP and generates a JSON output like this: {"scale":1.34,"x1":502,"x2":822,"y1":178,"y2":578} The image in question has dimensi ...

What could be causing the server to return an empty response to an ajax HTTP POST request?

Attempting to make a POST request using ajax in the following manner: $.ajax({ type: "POST", url: 'http://192.168.1.140/', data: "{}", dataType: "json", ...

Troubleshooting: Why isn't External CSS Functioning Properly in Broadleaf

I have encountered a question regarding the use of a custom email template in broadleaf. It seems that I am unable to apply an external CSS file and can only use inline styles. Is this normal behavior, or am I missing something? Below is how I am attempti ...

Ways to adjust image placement and size post-rotation with CSS/JS to ensure it stays within the containing div and avoids being cut off

Check out this jsfiddle I've been experimenting with. The jsfiddle is designed to rotate an image by 90 degrees in either clockwise or anti-clockwise direction upon button click. However, the rotated image currently appears outside of its parent div. ...

Ensure that both the div element and its contents are restricted to a maximum width of

I'm having trouble arranging the display of information next to a plant image. I want to ensure that the information stays on the right side of the image when the screen reaches a specific minimum width. The issue arises when the information includes ...

Tips for altering the color of an activated Bootstrap dropdown toggle

When the Dropdown menu is open, I would like to customize its default colors. Specifically, I want to change the border color and background using CSS. Below is the HTML code snippet: <div class="row menu"> <ul class="nav nav-pills pull-right"& ...

Tips for troubleshooting objects within an Angular template in an HTML file

When I'm creating a template, I embed some Angular code within my HTML elements: <button id="btnMainMenu" class="button button-icon fa fa-chevron-left header-icon" ng-if="(!CoursesVm.showcheckboxes || (CoursesVm.tabSelected == 'curren ...

Issues with inconsistent behavior of the select option in a form

Having some trouble with my form code. When I checked the web page, there seems to be an extra element that shouldn't be there. You can view the webpage . Inspecting it in browser developer mode, I found this extra element . Can you please help me ide ...