views:

266

answers:

8

Why margin:2.5px does not work? at one situation in my code i want to give margin:2.5px in IE6 conditional CSS to solve IE double margin and my default css has margin:5px but in IE6 css margin:2.5px and margin:2px creating same margin. then how to get same margin on both browser?

This is code of default screen CSS

    #newsHeadline LI 
{font-weight: bold; 
list-style-position: inside; 
font-size: 13px;
margin: 5px 0px;
width: 320px; 
line-height:
normal; list-style-type: disc; 
position: relative}

this is css code in conditional i'm writing #newsHeadline LI {margin: 2.5px 0px}

Edit: 15 feb

if margin:2.5px does not work then how to get same margin in both browser IE and FF? Is there any other way?

+5  A: 

Because px is the smallest unit possible. U really can't divide one display point, can you?

Edit: AS for your problem, if there is no interference with background (i.e. different color), you can try setting padding instead of margin for IE6.

Adam Kiss
Hah! That's what they said about atoms, too. I don't believe a word you say!
Pekka
@Pekka: Well... you don't want your LCD to produce electricity, do you? Then pixel splittin is big no no.@Andrew... why would you do such a thing?
Adam Kiss
@Pekka: Technically it should be possible to position text using sub pixel size. It's possible to position text to 1/3 of a pixel if you use ClearText aliasing. So I guess it could be possible. But only for text. Just to make it clear: I'd avoid such situation as well because it smells of problems.
Robert Koritnik
@Robert, I was only joking :) Though the sub pixel thing is interesting, now that you mention it. However, does ClearType really adress *sub pixels*? I always thought it does simple anti-aliasing with the background.
Pekka
Adam Kiss
@Adam Interesting! Thanks for the link.
Pekka
+2  A: 

You have to understand that a pixel is kind of like an atom. A pixel is the smallest discrete component of an image or picture on a screen.

Therefore, it is impossible to have half a pixel as it is already the smallest unit of measure possible. IE6 is properly interpreting the style in that case.

Andrew Moore
+1  A: 

A pixel is the smallest unit of display on your screen. Since nothing smaller can be displayed, so there is no way to place an item on the screen at a fractional pixel position.

Ray
I can show you how to move a black/white pixel (on inverted background) horizontally in 1/3 pixel increments on an LCD screen. Something ClearType does.
Robert Koritnik
Interesting. How does it work? Does it access the individual RGB elements of a pixel or something?
Ray
@Ray. Exactly. White pixel is still white if all three colors are lit no matter what order they are. RGB, GBR or BRG...
Robert Koritnik
pretty cool, but I wonder if it is (or will ever be) available to us poor html hacks, or if it requires low-level access to the graphics system to get any benefit.
Ray
+2  A: 

You can always set the box to display: inline, but that is not always what you want. Double margin affects block level elements.

As @Andrew Moore points out if you use this in your main stylesheet it will not be future proof and should be included in the IE6 stylesheet. Thanks.

Also, in some cases, you can use padding instead of margin since padding doesn't double. However, padding effects different properties of your layout and box model.

Thorn007
-1: Changing the `display` to `inline` only works now, until the browsers decide to follow the specifications on the matter. `inline` elements cannot have a set width and height and their dimensions are calculated based on their content and the current `line-height` of the parent element.
Andrew Moore
Thats why I said "but that is not always what you want" meaning he would want to drop that in the IE6 conditional comment. I Should have been more clear. Thanks for pointing this out :D
Thorn007
@Andrew Moore -- using "display: inline" in an IE-only stylesheet is the accepted way to deal with the IE double-margin bug. Since the technique will only ever be seen and interpreted by the broken Microsoft browsers in question, there's no "future failure" issue.
Pointy
@Pointy: In this case, that's fine, but the answer, before being edited, this not contain that information and was suggesting to apply `display: inline` globally.
Andrew Moore
@Andrew: that's not the case. If you float an element it becomes a block element and the display property has no effect. I'm pretty sure that's following the spec.
DisgruntledGoat
A: 

Why margin:2.5px does not work?

As others have pointed out already, a pixel is, by definition, the smallest unit, and thus can't be divided any further, by definition.

Then how to get same margin on both browser?

The usual fix is to set display: inline; on the element in question. In fact, some suggest to just apply the inline fix to all floats if you like, making sure that the fix only applies to IE5 and IE6 (e.g. by using conditional comments), since there are no known side effects in these browsers.

RegDwight
-1: No side effect right now, until the browsers decide to follow the specifications on the matter. `inline` elements cannot have a set width and height and their dimensions are calculated based on their content and the current `line-height` of the parent element.
Andrew Moore
@RegDwight - display: inline; not solving the problem
metal-gear-solid
+2  A: 

While plenty of people have suggested that the pixel is indivisible, and therefore a fractional pixel value makes no sense, the CSS standard does not actually rule out fractional values. Indeed, it suggests that when a high-resolution device is used, a CSS pixel unit should be mapped to a larger number of device-specific elements. My reading is therefore that 2.5px should not be explicitly wrong, just that you might not be able to rely on it to do something useful, especially, I might say, in Internet Explorer.

Tim
A: 

On the indivisibility of pixel: with the Zoom feature in modern browsers comes the notion of a "logical pixel". A smart enough implementation of zooming could and should use the fractional pixels...

Seva Alekseyev
A: 

you probably just need the fish fix

<ul
><li>content 1</li
><li>content 2</li
></ul>

remember no space between each ul/ol or li

Knu