Forum Moderators: not2easy

Message Too Old, No Replies

Negative Line-height -1

is this a hack?

         

Wlauzon

8:31 pm on Apr 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Came across this in our ecommerce site CSS, and am not sure if it is a bug (or attempted fix?), typo, or just bad code:

.clear {clear:both; display:block; font-size:1px; height:1px; line-height:-1;}

That is not the way I would do a clear, but perhaps I am missing something?

Since line-height cannot have a negative number not sure what to make of it.

[edited by: Wlauzon at 8:32 pm (utc) on April 30, 2008]

Setek

3:02 am on May 1, 2008 (gmt 0)

10+ Year Member



Sounds like they just want to make sure it takes up as little space as possible :)

I think IE would still make clear boxes bigger than 1px because of the font inside it, but most just use

overflow: hidden;
rather than a negative line height?

Wlauzon

5:10 pm on May 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem is, most browsers (any browsers?) ignore the statement as it is not valid.

But in a couple hours of searching I can find no reference to it being a bug fix, hack, or much else.

If this was our/my code I would just fix it or delete it, but the CSS has a few strange things in it, so am trying to track down the reasons for some.

For all I know, it might be a hack for Netscape 2.0 or DOS 3.1...

g1smd

6:21 pm on May 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



All numbers (except zero) must have units with them.

The -1 is not valid.

Wlauzon

7:14 pm on May 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually

{
line-height: 2
}

or {
line-height: 1.2
}

Etc is valid.

The -1 is not valid, which was what my question is about - I know it is not valid, but is it some obscure hack, or just a typo?

SuzyUK

3:05 pm on May 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



All numbers (except zero) must have units with them.

not so for line-height, it is perfectly valid, in fact it is recommended for line-height, g1smd - many don't get what inheritance does to line-height with a relative unit (it compounds!) see more on this [meyerweb.com]

Wlauzon.. I'd say it was someone's idea of a hack, it does and never did do anything, when IE had problems with empty divs all that was ever required was to set the font-size to 0 or 1px. (or overflow: hidden;)

I'd delete it!

[edited by: SuzyUK at 3:07 pm (utc) on May 7, 2008]

g1smd

7:57 pm on May 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Heh. Learn something every day. Thanks.

Wlauzon

10:19 pm on May 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Suzy - it sure is fun poring over someone elses CSS code and trying to figure out what they did and why.

If this was anything but an active online store I would just redo much of it, but that is not an option here, so having to make a few small changes at a time.

I just changed the line-height -1 to 1, and it did not seem to affect anything.