If you are reading this, please get modern browser.
skip to main content | skip to main navigation | skip to secondary content

Faux Borders and Pseudo Table Effect

~ 16th March 2005. · 13:35 CET · permanent link · printer friendly ~

Our recent project 24sata is living happily and after Vanja’s Two color sIFR and Two color sIFR Take Two articles, it’s now time for me to explain how I managed to position ‘comments’ and ‘read more’ links to bottom of every news preview box, which are all in the same row and of different amount of text within.

A few issues had to be taken into consideration:

  • Design composition required those links to be placed at the bottom of each news box, no matter how much text is in the box
  • Design also required that all the boxes in a particular row are of equal height and consistent no matter how much text is in the box

Wrapper to the Rescue

Three boxes had to be wrapped into some containing element (example 1), so we can float them to the left . (One must float everything inside also, to ensure expanding of the parent element. Even though it’s usually a good practice, in this particular case floating everything breaks layout in IE.) At this point, we can also set rules for width and borders of the boxes (example 2). As you can see boxes are not positioned where they should be, because wrapper’s width is set to 606px and boxes must be at the most 200px wide (plus margin of 2px). With 1px border, total width of those boxes is more than width of wrapper (mathematically: (200px width + 2px right-margin + 2 x 1px borders) x 3 boxes = 612px total width). We could have set width to 198px right away, but then again we would have to set a value back to 200px, once we deploy faux borders. Faux what? Oops! Keep reading…

Faux Border

In example 3 I made an image and placed it as the background of the wrapper, so we don’t need bottom and side borders of the news boxes, which now solves problem of news preview boxes being too wide. However, we need top border, because we can’t predict actual height of each box, since it depends on the amount of text within. Faux border background image is therefor positioned at the very bottom of the wrapper. This way we get the impression that boxes are extended to the bottom of the wrapper and are of equal height, even though they actually aren’t. Perfect! Now let’s go a little bit further…

Stuck Links to the Bottom

Next thing to do is positioning ‘comments’ and ‘read more’ link to the bottom of the wrapper (example 4), since the boxes are not as high as they appear to be. First of all, we add position: relative; rule for the wrapper. This ensures absolute positioning of ‘comments’ and ‘read more’ links relative to wrapper, not to the corresponding boxes (which are of different heights, remember?). Since we can add class names cnt1, cnt2 and cnt3 to the boxes, we can safely position each of them separately.

.smallBox .subNav { position: absolute; bottom: 0; }
.cnt1 .subNav { left: 0; }
.cnt2 .subNav { left: 202px; }
.cnt3 .subNav { left: 404px; }

(.smallBox and cnt1 etc. are two different class names at the same element).

Also, we must establish bottom padding of the boxes, since the links are positioned absolute, so they are out of the flow. Without bottom padding, text in the longest box would fall behind the links. To fix this, we can increase padding bottom by 1em (or whatever line-height of the links is), to ensure that text in the boxes doesn’t fall behind.

Final Touch

Finally, we have to move ‘comments’ link to the left and ‘read more’ link to the right (example 5). To achieve that, just float parent element (in this case <ul>) and both <li>s (which are carrying links) to the left. For <li> which carries ‘read more’ link we should shift text to the right by adding text-align: right; rule. We should also set some width and paddings to both <li>s, so they do not collide.

.subNav li { list-style: none; width: 90px; float: left; }
.readMore { text-align: right; }

And that’s pretty much it… Any thoughts?

12 Comments

  1. Very neat, one for the bookmarks! :-)

  2. I think it’s a unique technique and I’m with Oxton, it’s one to save for the bookmarks. Thanks for sharing!

  3. Nice technique.

    Hvala Marko. Pozdrav iz Londona

  4. Nice, but doesnt work in IE6 to me?

  5. Crap! I missed to check for the floating bugs in IE. It’s fixed now : ). However, adjusting for IE 5.x requires more hacking, which is out of the context of this topic.

  6. I’d recommend using .subNav li:first-child and .subNav li:last-child to select the LIs, as it will mean less repetition in the source.

    Firefox will understand what you mean, and you can get IE to understand it by applying Dean Edwards’ IE7 patch (ie7.sf.net)

    btw: your “preview” comment thing slows my poor laptop to a crawl.

  7. @Kae: As Dean Edwards wrote:

    “Remember this is alpha software. I’m still developing this solution, what you are looking at is a work in progress. It is not advisable to use IE7 on a commercial web site until it becomes at least beta software.”

  8. Good explanation of interesting solution.

  9. Just stumbled across this. Interesting article, although I’ve still to find a solution that works for liquid designs.

    All of these “faux techniques” rely on fixed width images which obviously wont resize. Has anybody found a solution for liquid designs?

    Is probably the only scenario where I still end up having to use tables.

  10. could you place an invisible image in the containers which forces the height width to a particular size? Or is that what you are doing in the background div.

    Roan,
    here is a method I came up with but not as elegant because it uses scroll bars:
    http://esearing.com/webDev/mockups/3ColsNested.html

  11. Excuse me but…
    “(100px width + 2px right-margin + 2 x 1px borders) x 3 boxes = 612px total width)” is not quite correct ;) You probably meant 200px (as I can see width of boxes in examples).
    Anyway it does work in IE6.
    Regards

  12. Ouch! Five months nobody saw that :)

Sorry, the comment form is closed at this time, but if you have anything to say, please send me a message.

* Please keep in mind that this is a personal web site and it does not reflect the position or opinion of my respective employers, organizations or partners.

Typetester – compare screen type Supported by Veer.

What is this?

A web log of Marko Dugonjić, web professional from Croatia. Topics covered:

Translate this site

German, Spanish, Italian, French or Japanese (via).

See you there!

Feel like buying a book?

Try with maratz.com aStore

Worth visiting

top of the page | skip to main content | skip to main navigation | skip to secondary content