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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T13:05:53+00:00 2026-05-22T13:05:53+00:00

I have a layout where images float within a certain area. The layout looks

  • 0

I have a layout where images “float” within a certain area. The layout looks like this:

Layout Example

The source like this:

<div class="free_tile">
  <a class="img_container canonical" href="/photos/10">
    <img class="canonical" src="http://s3.amazonaws.com/t4e-development/photos/1/10/andrew_burleson_10_tile.jpg?1303238025" alt="Andrew_burleson_10_tile">
    <!-- EDIT: I am aware that I can put the badge here. See the edit notes and image below. -->
  </a>
  <div class="location">Houston</div>
  <div class="taxonomy"> T6 | Conduit | Infrastructure </div>
</div>

The CSS looks like this (in SCSS):

div.free_tile { width: 176px; height: 206px; float: left; margin: 0 20px 20px 0; position: relative;
  &.last { margin: 0 0 20px 0; }
  a.img_container { display: block; width: 176px; height: 158px; text-align: center; line-height: 156px; margin-bottom: 10px; }
  img { margin: 0; border: 1px solid $dark3; display: inline-block; vertical-align: middle; @include boxShadow;
    &.canonical { border: 1px solid $transect; }
  }
  .location, .taxonomy { width: 176px; }
  .location { font-weight: 700; }
  .taxonomy { line-height: 10px; font-size: 10px; text-transform: uppercase; height: 20px; overflow: hidden; }
}
div.transect_badge { height: 20px; width: 20px; background: url('/images/transect-badge.png'); }

So, basically the images are sitting vertically-aligned middle and text-aligned center, and they have a maximum width of 176 and max height of 158, but they’re cropped to maintain the original aspect ratio so the actual top corner of each image falls differently depending on which image it is.

I have a badge that I’d like to put in the top corner of certain images (when the image is “canonical”). You see the style for this above (div.transect_badge).

The problem, of course, is I don’t know where the top corner of the image will be so I can’t hardcode the position via CSS.

I assume that I’ll need to do this via jQuery or something. So, I started with a jQuery method to automatically append the badge div to any canonical images. That works fine, but I can’t figure out how to position it over the top left corner.

How can this be done? (ideally using just HTML and CSS, but realistically using JS/jQuery)

–EDIT–
Here’s the problem: The image is floating inside a container, so the corner of the image might fall anywhere inside the outer limits of the container. Here’s an example of what happens if I try to use position:absolute; top:0; left:0 inside the same container the image is bound by:
The problem

  • 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-05-22T13:05:53+00:00Added an answer on May 22, 2026 at 1:05 pm

    It took some tryouts, but here it is: the size independent image badge positioner.

    HTML:

    <div class="tile">
        <span class="photo">
            <a href=""><img src="/photos/10.jpg" alt="10" /><ins></ins></a>
        </span>
        <p class="location">Houston</p>
        <p class="taxonomy">T6 | Conduit | Infrastructure</p>        
    </div>
    

    CSS:

    .tile {
        float: left;
        width: 176px;
        height: 206px;
        margin: 0 20px 20px 0;
     }
    .photo {
        display: block;
        width: 176px;
        height: 158px;
        text-align: center;
        line-height: 158px;
        margin-bottom: 10px;
    }
    a {
        display: inline-block;
        position: relative;
        line-height: 0;
    }
    img {
        border: none;
        vertical-align: middle;
    }
    ins {
        background: url('/images/badge.png') no-repeat 0 0;
        position: absolute;
        left: 0;
        top: 0;
        width: 20px;
        height: 20px;
    }
    

    Example:

    In previous less successful attempts (see edit history), the problem was getting the image vertically centered ánd to get its parent the same size (in order to position the badge in the top-left of that parent). As inline element that parent doesn’t care about the height of its contents and thus remains to small, but as block element it stretches to hís parent’s size and thus got to high, see demonstration fiddle. The trick seems to be to give that parent a very small line-height (e.g. 0) and display it as an inline-block. That way the parent will grow according to its childs.

    Tested in Opera 11, Chrome 11, IE8, IE9, FF4 and Safari 5 with all DTD’s. IE7 fails, but a center-top alignment of the photo with badge at the right position isn’t that bad at all. Works also for IE7 now because I deleted the spaces in the markup within the a tag. Haha, how weird!

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

Sidebar

Related Questions

I have a layout similar to this: <div id=...><img src=...></div> and would like to
I have an annoying CSS layout problem. I'm trying to float images on a
I have achieved to do this (a form layout) ... form layout http://www.stan.com.mx/images/CSSDoubt1.gif ...
I am using Tiles within my web-application. I have a standard-layout (standard.jsp) within the
I have the following div layout: Everything is fine when I put normal txt
I cannot get this last div to go up properly in my layout and
In the HTML below, the layout works when the actionBar class has a float
I have a linear layout that contains 6 images, which span the linear layout
HTML: <br /> <div class=UpperTitle> <img src=Images/CableSolve Logo.jpg align=absmiddle padding-right: 10px; /> CableSolve Web
I want to do something like this: .even { float: left; text-align: left; }

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.