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

CSS Padding Hover Transition solution for Eliminating Flickering Text issue

Is it possible to achieve this? I'm attempting to animate the padding around a centered text link. When the text link is clicked, the padding changes from 20% to 100%, which works correctly. The text is horizontally and vertically centered using CSS ...

How do I navigate to a different page in Vue.js HTML based on user selection?

Here is my first attempt at writing HTML code: <div class="col-md-4" > <div class="form-group label-floating"> <label class="control-label">Select No</label> <select class="form-control" v-model="or" required=""> ...

Enhancing WordPress Menu Items with the 'data-hover' Attribute

Looking for a solution to add "data-hover" to menu items on Wordpress, like: Wanting to insert: data-hover="ABOUT US" into <a href="#">ABOUT US</a> without manually editing the link's HTML to make it: <a href="#" data-hover="ABOU ...

Tips for ensuring a scrollbar remains at the bottom position

I'm facing an issue with a scroll-bar inside a div element. Initially, the position of the scroll-bar is at the top. However, whenever I add text to the div element, the scroll-bar remains in its initial position and does not automatically move to the ...

What is the process for displaying objects within an object using HTML?

I'm developing an app using Angular and Node.js. I have a complex data structure where one object (order) contains a list of objects (items), which in turn include another list of objects (product IDs). My goal is to properly display all this data wit ...

Presentation and selection list

Here is the CSS code I am using: .nav li a { background-color:#000; color:#fff; text-decoration:none; padding:10px 15px; display:block; } .nav > li { float:left; } .nav li a:hover { background-color:#4db4fa; } .nav li ul { ...

How can I hide or remove the pesky three dots "..." from appearing in any HTML elements?

While working on a project in VueJS, I've noticed that whenever I add a new class to an HTML tag, it displays as class="..." This is something that bothers me, and I'm not sure if it's due to a recent extension I installed or if i ...

What is the correct method in CSS to resize an image while maintaining its proportions within a div container?

I've been struggling to properly insert images into a <div> element on my website. I've experimented with various techniques, such as setting max-width and max-height to 100%, changing the display property of the parent element to flex, and ...

Varying heights based on the screen size

Currently, I am in the process of designing my website and incorporating some wave elements to enhance the background. However, I've encountered some issues when resizing the screen. Specifically, the waves seem to shift with a space between them as t ...

CakePHP does not recognize the input type "number" in forms

My goal is to create a form field that only accepts numbers as input. However, when I attempt the following code in CakePHP: <?php echo $this->Form->input('aht',array( 'label' => 'AHT', 'type' = ...

Tips for arranging headers next to each other on a restaurant menu

I'm currently working on a website for a local restaurant, my very first project of this kind. As I draft the menu section, I'm struggling with displaying Starters and Main Courses side by side on the screen. Additionally, the layout falls apart ...

Customizing Material-UI: A guide to overriding inner components

Looking to customize the styles of a Material UI Switch for the small variation? I have applied global styles but now want to override the styles of elements like track and thumb. Targeting the root element with the sizeSmall class is working, but unsure o ...

The hover effect for changing the style of one element when hovering over another element is not functioning as

I've encountered an issue with styling a triangle element using the .something:hover .another{...} selector. Can anyone help me understand what might be causing this problem? .actions { display: flex; margin-top: 20px; max-width: 260px; } .a ...

There is a significant spacing issue between the header and main category when viewed on a mobile device

Experiencing issues with element distances on different screen sizes? While the website looks fine on normal screens, there's a noticeable gap between the header and main sections on mobile devices. See below for the provided HTML and CSS code. ...

Reducing Image Size for Logo Placement in Menu Bar

Hello all, I am a newcomer to the world of web coding. Please bear with me if I ask something that may seem silly or trivial. I recently created a menu bar at the top of my webpage. Below that, there is a Div element containing an image. My goal is to make ...

Javascript function for downloading files compatible with multiple browsers

When working with a json response on the client side to build content for an html table, I encountered an issue with saving the file to the local disk upon clicking a download button. The csvContent is generated dynamically from the json response. Here&ap ...

Internet Explorer experiencing off-screen menu loading issue

Currently, I am in the process of developing a website for my sister but facing challenges with cross-browser compatibility. The menu appears off-screen when using Internet Explorer, while it looks fine on Chrome. Despite various attempts to adjust alignme ...

How can I adjust the indentation in Angular Prime-ng's p-tree component?

In my project, I am utilizing the primg-ng tree component for the sidebar. Currently, the output is displayed as shown here: https://i.stack.imgur.com/kcSQt.png However, I am looking to maintain consistent indentation levels without any adaptive changes ...

The Bootstrap 4 navbar remains consistently visible on mobile devices

I am experiencing an issue with my bootstrap navbar on mobile devices. It remains visible even when the navbar-toggler is collapsed. Below is the code snippet: <nav class="navbar navbar-expand-lg navbar-light bg-light"> <div class="container"&g ...

Exploring how enums can be utilized to store categories in Angular applications

My application has enums for category names on both the back- and front-end: export enum CategoryEnum { All = 'All', Category1 = 'Category1', Category2 = 'Category2', Category3 = 'Category3', Cate ...