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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:37:32+00:00 2026-06-14T09:37:32+00:00

I have the following html: <div class=container> <img src=…/> <p>Heading</p> </div> I want this

  • 0

I have the following html:

<div class="container">
    <img src="..."/>
    <p>Heading</p>
</div>

I want this behaviour:

  • If there is no image (no <img> tag) the p should dictate the size of the .container.
  • If there is an image, but the p is taller the .container should be as tall as the p.
  • If the image is taller the .container should be as tall as the image and the p should “grow” from the bottom of .container and up depending on the amount of text in it (like position:absolute; bottom:0 inside a position:relative box).
  • The p should have a background that should be semi transparent so you can partially see the image through the element. The transparency is not the issue, but I include this as I don’t want a solution that makes the p take the full height of the .container and then repositions the text.
  • It has to work in IE8 (only required browser).
  • I can freely manipulate the html structure if needed, but I’d like to keep it as simple as possible.

I can do it trivially with javascript, but is it possible to do with pure CSS?

(this codepen shows partially what I’m trying to do: http://codepen.io/anon/pen/sqjnz)

Edit for clarification: I want .container to be as tall as the tallest child (img or p). If both the img and p are present the text should be on top of the image and anchored at the bottom of .contianer so as it grows it covers more and more of the image. If there is no image (the img tag is not present) the box should behave like a normal div and expand to the same size as the p.

  • 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-14T09:37:33+00:00Added an answer on June 14, 2026 at 9:37 am

    Is this what you’re after?

    <div class="container">
        <img src="http://lorempixel.com/100/100"/>
        <p>Heading</p>
    </div>​
    

    and CSS:

    .container {
        /* these are just set so we can see the size of container */
        margin: 20px;
        padding: 5px;
        background-color: #eee;
    }
    .container img {
        margin-right: -100px;
        vertical-align: bottom;
    }
    .container p {
        display: inline-block;
        width: 100px;
        background-color: rgba(0,0,0,.75);
        line-height: 1em;
        color: #fff;
        vertical-align: bottom;
    }​
    

    And to accomodate IE into the mix with semi-transparency I suggest you read Lea Verou’s blog post.

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

Sidebar

Related Questions

I have the following HTML <div id=testID class=test1> <img id=testID2 class=test2 alt= src=some-image.gif />
I have the following HTML code: <div class=outer_container> <div id=imgContainer> <img src=/some/image /> </div>
I have the following html markup: <div id=com_loaded> <div id=com_loaded_userpic><a href=# class=tooltip><img src=pic.jpg class=img_poster
Suppose I have the following html: This a test of <code>some code</code>. <div class='highlight'>
I have this html configuration: <div id=Header> <div id=Stamp> <img alt=Header Stamp src=images/About-Us.png />
For the following HTML: <li id=li1> <div id=card-container> <div id=card> <div class=front> <img id=track_image
I have the following HTML in a page: <a href=javascript:void(0) class=move-next><img src=/Content/images/small-next-arrow.png height=16 width=16
I have a seemingly simple html construct: <div class=featured-image img-wrapper full-width> <a href=http://localhost/wordpress/?p=26> <img
I have the following html- <div class=container> <h1 class=page-header id=property_head>A cool title</h1> <div class=row
I have the following html structure <div id=container> <div class=label> @Html.LabelFor(m => m.SomeProperty) </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.