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 8122155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:44:19+00:00 2026-06-06T05:44:19+00:00

Suppose I have a div with the following styles applied: div { border: 1px

  • 0

Suppose I have a div with the following styles applied:

div {
    border: 1px solid #000;
    padding-left: 35px;
    position: relative;
}

To that div I apply a :before pseudo-element. The content of that pseudo-element is an image:

div:before {
    content: url(someImage.png);
    background-color: #ccc;
    position: absolute;
    left: 0;
    width: 30px;
    height: 100%;
}

The height of the div is dynamic. Is there any way I can vertically center the image that is part of the generated content?

Here’s a fiddle with an example.

I can’t use line-height since I don’t know the height of the div. I can’t use a margin or padding since the generated content has a background colour that would expand beyond the div. I suspect the answer is “no”, but thought it might be worth asking here before I have to go and change a lot of markup!

  • 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-06T05:44:20+00:00Added an answer on June 6, 2026 at 5:44 am

    It should theoretically be possible as it’s nothing more than a CSS version of a regular inline <img> tag, but that depends largely on its formatting (and possibly that of the generating element).

    For simplicity, I would make it a background image instead, with an empty string for its content:

    div:before {
        content: '';
        background: #ccc url(someImage.png) center center no-repeat;
        position: absolute;
        left: 0;
        width: 30px;
        height: 100%;
    }
    

    Notice that I’m taking advantage of the fact that you already have the gray background adequately covering the generated area — I simply center the image over that gray background.

    Updated fiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have the following CSS snippet: div { width: 200px; padding: 10px; border-width:
Suppose I have the following HTML: <div id=test> <span style=display:inline;>foo</span> <span style=display:none;>bar</span> <span style=display:inline;>baz</span>
Suppose I have the following html: This a test of <code>some code</code>. <div class='highlight'>
Suppose I have an div. Inside this div, I have two divs floating left,
Suppose I have the following html: <div style=width:200px;height:200px;overflow:scroll> ... </div> If the stuff in
let's suppose to have following code: <body style=overflow: hidden> <div class=wall> <button>New</button> <div class=prova>
Suppose I have the following HTML: <div class=container> <span class=remove>remove</span> </div> and jquery: $(.container).delegate(.remove,
Suppose I have the following HTML and js <div> <div class=testdiv id=test1>test</div> <div class=testdiv
Suppose I have the following html: var testString = ' <span id='id'> <div> <table>
Suppose I have the following HTML: <div id=Wrapper> <div class=MyClass></div> <div class=MyClass></div> <div class=MyClass></div>

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.