What are the steps to fixing a CSS problem in order to show an image caption?

Looking to enhance image display by adding captions? Check out the CSS and HTML code provided below:

   <style type="text/css">

    .caption-style-1{
        list-style-type: none;
        margin: 0px;
        padding: 0px;

    }

    .caption-style-1 li{
        float: left;
        padding: 0px;
        position: relative;
        overflow: hidden;
        margin-right:5px;
    }

    .caption-style-1 li:hover .caption{
        opacity: 1;

    }

    .caption-style-1 .hover-effect{
        margin: 0px;
        padding: 0px;
        float: left;
        width:220px;
        height:150px;
        //background-color:#999;
        margin-bottom:5px;
    }

    .hover-effect img{
        margin: 0px;
        padding: 0px;
        float: left;
        z-index: 4;
    }
    .hover-effect h1
    {
        font-size:20px;
        border:solid 1px red;
    }

    .hover-effect p
    {
        font-size:13px;
        margin:0;
        padding:0;
    }


    .caption-style-1 .caption{
        cursor: pointer;
        position: absolute;
        opacity: 0;
        -webkit-transition:all 0.45s ease-in-out;
        -moz-transition:all 0.45s ease-in-out;
        -o-transition:all 0.45s ease-in-out;
        -ms-transition:all 0.45s ease-in-out;
        transition:all 0.45s ease-in-out;

    }
    .caption-style-1 .blur{
        //background-color: rgba(0,0,0,0.65);
        height: 150px;
        width: 220px;
        z-index: 5;
        position: absolute;
    }

    .caption-style-1 .caption-text h1{
        text-transform: uppercase;
        font-size: 10px;
    }
    .caption-style-1 .caption-text .blur{
        z-index: 10;
        color: #fff;
        position: absolute;
        width: 220px;
        height: 150px;
        text-align: center;
        background-color: rgba(0,0,0,0.65);
    }

    /** Nav Menu */
    ul.nav-menu{
        padding: 0px;
        margin: 0px;
        list-style-type: none;
        width: 490px;
        margin: 60px auto;
    }

    ul.nav-menu li{
        display: inline;
        margin-right: 10px;
        padding:10px;
        border: 1px solid #ddd;
    }

    ul.nav-menu li a{
        color: #eee;
        text-decoration: none;
        text-transform: uppercase;
    }

    ul.nav-menu li a:hover, ul.nav-menu li a.active{
        color: #2c3e50;
    } 

    .opacity
    {
        opacity:0.2;
        filter:alpha(opacity=20); /* For IE8 and earlier */
    }

    </style>

Check out the following HTML code snippet for an example of how to implement the captioned images:

<ul class="caption-style-1">
   <li>
     <div class="hover-effect">
         <div class="opacity"><img src="img/chaps_1x.jpg" width="220px" height="150px" alt=""></div>
          <h1>Amazing Caption</h1>
      <p>Whatever It Is - Always Awesome</p>
     </div>

     <div class="caption">
    <div class="blur"></div>
      <div class="caption-text">
        <img src="img/chaps_1x.jpg" width="220px" height="150px" alt="">
      </div>
    </div>
    </li>
</ul>

Feeling inspired?

Answer №1

Your HTML code needs some improvement in its structure. If you are working with HTML5, consider using specific HTML5 tags such as figcaption within figure. The issue with the Caption tag not displaying properly is likely due to it being positioned behind the image.

To bring elements to the front, you can utilize the z-index property as shown below:

 .hover-effect h1
    {
        font-size:20px;
        border:solid 1px red;
      position:fixed;
        z-index:999;
    }

    .hover-effect p
    {
        font-size:13px;
        margin:0;
        padding:0;
       position:fixed;
        z-index:999;
    }

Check out the Demo here: http://jsbin.com/yegiyico/1/

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

Explore the input from multiple users to uncover the word that appears most frequently among them

Hey there (brand new to JavaScript), I am working on a simple program that requires input from multiple users through prompt pop-ups. For example: <script type="text/javascript> var userInput = prompt("Enter your input:"); </script> It&ap ...

Tips for maintaining HTML lines within an 80-character limit

Someone mentioned to me the importance of keeping HTML lines under 80 characters. My code editor, Atom, even displays a reminder for this limit. I've come across many discussions on this topic but haven't found any examples. For instance, consid ...

Optimizing FileReader result for seamless compatibility on all browsers and devices when loading into an HTML5 video player

I want to implement a feature where the selected video file can be loaded into an HTML5 element for users to preview before sending it to the server. However, I am encountering an issue with compatibility on Chrome and Safari browsers, both on desktop and ...

Issue with Angular: Mobile view toggle button in the navbar is unresponsive

While the dropdowns are functioning correctly in web mode, the navbar toggle isn't working as expected in small screens or mobile mode. I've been trying to figure out the issue by referring to code from CodePen that I am learning from. Despite i ...

Should one consider utilizing Ionic for creating a mobile web variant of a website?

Working for a Startup, we made the decision to create an adaptive website instead of a responsive one. This means that we serve different views for different devices in order to provide the best user experience for both mobile and desktop users. We are c ...

Shuffle and Arrange Divs - Slick.JS

Incorporating the slick.js library, I have implemented the following code snippet in my web page to shuffle the slides within the carousel. JavaScript/jQuery: $('.qa').on('init', function(event, slick, currentSlide, nextSlide) { / ...

Text in React Native exceeding one line is causing it to extend beyond the screen boundaries

I am having trouble displaying the last messages in my simple contact list as the text is getting cut off the screen. Below is the code I am using: (the readableTimestamp should be positioned behind the text.) View style={{ fontSize: 16, backgro ...

"Changing background color, incorporating hover effects, utilizing !important, and manipulating .css properties with

Encountered a dilemma. I devised a "tabs" feature illustrated in the following demo: http://jsfiddle.net/4FLCe/ The original intention was for the tab to change color to A when hovered over, and to color B when clicked on. However, as shown in the demo, ...

Issue with Collapse Feature on Bootstrap 3.x Navbar

The Bootstrap 3 Navbar expands properly in full screen and on a browser with a small width on a desktop PC and mobile browsers, but when using the Toggle navigation button, it doesn't slide down. I have tried to replicate the code from this example: h ...

What is the best way to ensure that the question text will wrap onto a new line if it becomes too lengthy

I am currently working on developing ASP.NET MVC applications. However, I am facing a design issue with the HTML, CSS, and Bootstrap elements on one of my pages. The problem arises when Question 8 exceeds the border and does not wrap to a new line as inte ...

The presence of text is leading to CSS placement troubles

I operate a website dedicated to comic content and am looking to incorporate text (retrieved from the database field "description") beneath each comic thumbnail. Here are my two inquiries: 1) I'm facing an issue where adding text below a comic caus ...

Tips for Aligning Form Elements in the Middle using Bootstrap

What could be the issue? I can clearly see the container border, indicating the space available for my work. However, when I insert the row (div) and offset (div), the content gets left-justified. <div id="page" class="container" style="border:soli ...

Modifying CSS stylesheet does not alter the background color

body { background-color: bisque; } <!DOCTYPE html> <html> <head> <title>Reading</title> </head> <body> <h1> <button><a href="index.html">Home</a></button> & ...

What are the style attributes that can be edited in each ant design component?

My goal is to customize an ant design card by adding a border only on the left and right sides of the card. The bordered attribute in the card component seems to either remove the entire border or display it on all sides. I am looking for a way to specif ...

What is the best way to insert an image that is absolutely positioned inside a <td>?

I'm facing an issue with placing an absolutely positioned image inside a td. The code I have tried seems to create gaps above the image in FF 3.6 and causes the image to disappear in IE 7. I have included the necessary external style sheet elements ab ...

Guide for verifying the minimum and maximum values when selecting a particular product from a dropdown menu

My goal is to implement validation for the width textbox when a user selects a specific product from the dropdown menu. The validation should only allow the user to enter a value between 10 and 200. I have successfully retrieved the selected value, but I ...

Is it feasible to simultaneously activate a modal and launch a URL in a separate tab when a link is selected?

I have 4 buttons, stylized to look like actual buttons, but only two of them are relevant: The first button opens a link in a new tab with its respective URL and the attribute target="_blank". The second button triggers a modal window containing text ...

The dimensions of the pop-up window in Chrome's JavaScript are not displaying correctly

My goal is to launch a new chat room window on our website. The dimensions of the chat room are set to 750px x 590px. Below is the link I am using to trigger the javascript popup. <a href="javascript:void(0)" onclick="window.open('http://gamersuni ...

Angular not updating the values in real time

First and foremost, I am utilizing socket.io to emit data. Data is emitted upon connection (so the website does not appear blank) as well as when certain events occur. Upon initial connection or page refresh, everything updates and functions smoothly. Howe ...

Using jQuery to completely replace the DOM with new HTML content by utilizing the .load method

I'm currently facing an issue with a Captive Portal implementation on my website. Here's the scenario: go to any site, like www.php.net, and then in Chrome's console, execute the following code: $("html").load( "https://www.ccc.co.il/Suspe ...