Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9169505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:53:19+00:00 2026-06-17T15:53:19+00:00

Before we start: Please don’t close this as a duplicate of another question. I

  • 0

Before we start:
Please don’t close this as a duplicate of another question. I just searched here on Stackoverflow without finding that exact case.

The closest is I believe this question. Still, the replies given there don’t really work for me, I believe because the paragraph is set position: absolute;.

Thats the HTML:

<ul>
    <li><img src="http://www.placehold.it/300x200" /><p><span>Lorem Ipsum</span></p></li>
</ul>

And the CSS:

li {
  position: relative;
  float: left;
  overflow: hidden;
}

img {
  width: 100%;
  vertical-align: middle;
}

p {
  background-color: rgba(255, 0, 0, .3);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

span {
    background-color: rgba(0, 255, 0, .3);
    vertical-align: middle;
}

Fiddle: http://jsfiddle.net/DpVjZ/

vertical-align: middle; just bumps the text a tiny bit away from the top, but not really in the middle.
Setting the span position: absolute; and then applying top: 50%; and then margin-top: -x%; won’t work because the height of the span is not known as it is dynamic content.
Although the linked question states that this is bad practice, I also tried the display: table-cell approach without any result. Please help me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:53:19+00:00Added an answer on June 17, 2026 at 3:53 pm

    Get rid of the p tag. You already have it in a li anyway.

    css

    li {
    position: relative;
    float: left;
    overflow: hidden;
    }
    
    img {
    width: 100%;
    height: 100%;
    }
    
    span {
    background-color: rgba(0, 255, 0, .3);
    position: absolute;
    text-align:center;
    width: 100%;
    top:46%;
    }
    

    html

    <ul>
    <li><span>Lorem Ipsum</span><img src="http://www.placehold.it/300x200" /></li>
    </ul>
    

    Tested on window IE9 and Chrome.

    Don’t know if it was for the demo or not but if you want the red shade over the image make a class for a span tag then insert a new span with the class.

    span.text {
    background-color: rgba(0, 255, 0, .3);
    position: absolute;
    text-align:center;
    width: 100%;
    top:46%;
    }
    
    span.redshade {
    background-color: rgba(255, 0, 0, .3);
    width: 100%;
    height: 100%;
    
    <ul>
    <li><span class="redshade">&nbsp;</span><span class="text">Lorem Ipsum</span><img src="http://www.placehold.it/300x200" /></li>
    </ul>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Before I start, please don't yell at me telling me the answer is here
Am using Mediainfo library in my C# project,before start invoking this dll,i just ran
before I start I want to point out that I tagged this question as
Please don't consider it a duplicate before reading, There are a lot of questions
Before u start: I searched the google and stackoverflow, none of them gave clear
Before I start, please accept my apologies that I'm not a mathematician and don't
I searched, did not find this question asked before (it is NOT the same
(Before I start, yes I have asked a similar question before; unfortunately due to
First off, I'm doing this for myself so please don't suggest use GMP /
Before you start admonishing me with DON'T DO IT , BAD PRACTICE ! and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.