Source Guru

Hacky HTML

by Mez on Dec.09, 2008, under Personal

Ok, so working on a new site, I’ve realised that an image I’ve floated to the right of my text seems to be overlapping the items beneath it.

Ok, so, that’s obviously not what we want!!!!

Normally, I’d use clearfix for this, however, I have the issue that I will also be using a sidebar (at times) and well, clearfix will interfere with this:-

So, that’s obviously not something we want! – I had to find a nice way of doing this, without it interfering with everything else!

I thought about this, and thought I’d do a bit of voodoo with CSS and make this work!

Yay! It worked!

How’d I do this you may ask. Well, the containing div needed the following CSS (which also, quite niftily extends the height of the float if it’s the shorter one, making it the full height of the containing div

overflow: hidden;
padding-bottom: 32767px;
margin-bottom: -32767px;

The only issue? – It doesn’t work in any Internet Explorer Version, or Opera <= 8 – though it works in pretty much every other browser (according to browsershots)

*sigh* back to the drawing board, unless anyone else has some suggestions?

Edit: I was wrong – it works in IE7, but not in IE8
Edit 2: and it works in IE8 if you tell it to run in IE7 compatibility mode

:, ,

9 Comments for this entry

  • jim

    if all the images have the same height you could try with a min-height directly in the div which contain the description

  • Sander

    You could try floating the parent container too, that should solve the problem: See http://www.yongfook.com/items/view/81/10-dirty-little-web-development-tricks (#7)

    As far as I know that works in every browser. Usually saves me a lot of hassle :)

  • tsb

    I don’t quite see the problem but honestly, how about spending time on things that matter and just use a table for this?

  • Dotan Cohen

    You have code that works in Firefox/Opera/IE7 but not IE 8? That is unusual. Does the code ([X]HTML and CSS) pass W3C validation?

    Don’t declare IE7 compatibility. It is the browser’s job to display legal code, not the website’s job to hack for any one browser. Put a disclaimer at the bottom declaring that the site does NOT work in IE, like this site does:
    http://what-is-what.com/

    When we stop bending over backwards to support IE, then the users will conclude that IE is broken and not the web. Those who insist upon using a broken web browser can see broken webpages.

  • Mez

    jim:- The images aren’t neccessarily all the same height. The min-height can be generated, but won’t work on all browsers

    Sander:- this shoves things around a little – and makes things not span the full page, but if I do that and add a width: 100%; it does work! yay!

    tsb:- Semantic Markup, accessibility, the list goes on. Tables are for tabulated data, not for layout.

    Dotan, thing is, I don’t want to alienate users… and yes, the CSS is valid.

  • parena

    I’ve seen the huge negative margin hack cause another problem: non-working anchorst (clicking on a link to an anchor within the same page would simply do nothing), though I’m not sure it might have been caused by a combination of that hack together with other (bad) CSS.

  • tsb

    @ mez: yes I know. But if there is a corner-case where it is hard to get it right and consistent, and it is a small and insignificant thing (ie not the whole site), I don’t think it’s going to matter (I did when I first started becoming tableless-infected years ago). The avoid-tables-at-all-costs is a bit hysterical IMHO. If you could specify things like hight-dependence among divs (css3) then it would be no need for them. But like it is presently, you have to use all sorts of divs in a div in a div, and that’s not necessarily so semantic either; it’s something of a hack.

    So what I meant was, I’ll make the page based on css and semantics, of course, but if I am having big problems with some insignificant small thing I’m not opposed to just slapping a table on it, call it a day and work on the product that matters instead.

  • Zarquod

    Look at the clearfix article on PositionIsEverything again and you’ll find a box at the top with a red border around it. Follow the link inside and you have your solution. Just add “overflow:auto” to the parent element.

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!