麥克斯做個不宅的工程師

Maxi’s idiotic programming.

CSS positioning and layout in FX and IE

If you have a background image for your website, you made found some strange spacing on the top and left of your background. Usually only occurs in IE, sometimes FX too.

It is because <html> and <body> have some strange default spacing.

Anyway, add this to your CSS and fix it.

html, body, form, fieldset {
    margin: 0;
    padding: 0;
}

And I found out that empty <div> in IE have a strange 1px height problem.

Here are three fix that people said it works.

1) Put a comment inside the

2) Put inside the

and add this to its style: font-size:0px;
line-height:0.
3) Setting your website to strict mode by using this DOCTYPE

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

1+3 should work well enough.

BTW, here is the position value that I always forget their meaning.

Value Description
static Default. An element with position: static always has the position the normal flow of the page gives it (a static element ignores any top, bottom, left, or right declarations)
relative An element with position: relative moves an element relative to its normal position, so “left:20″ adds 20 pixels to the element’s LEFT position
absolute An element with position: absolute is positioned at the specified coordinates relative to its containing block. The element’s position is specified with the “left”, “top”, “right”, and “bottom” properties
fixed An element with position: fixed is positioned at the specified coordinates relative to the browser window. The element’s position is specified with the “left”, “top”, “right”, and “bottom” properties. The element remains at that position regardless of scrolling. Works in IE7 (strict mode)

Cheers :D

May 15, 2008 , Thursday Posted by maxi326 | Web | , , | No Comments Yet

Transparent PNG, IE and FX compatible

The best practice of transparent image is always use .png instead of .gif .

.gif should used for animation, because .png have more color and do more elegant transparency. Static image should always use .png .

But when you view your transparent .png in IE, It will have a background color.

This is another problem caused by mighty IE…

Here is how you fix it by CSS, there are many other fix though.

I like this CSS fix because it follows the separation of content and style rule.

IE

#ID {
background-image: none;
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="resources/images/UL_corner.png", sizingMethod="scale");
}

Others Browser

html>body #ID {
background-image: url(../images/UL_corner.png);
}

Possible value for sizingMethod:

crop Clips the image to fit the dimensions of the object.
image Default. Enlarges or reduces the border of the object to fit the dimensions of the image.
scale Stretches or shrinks the image to fill the borders of the object.

Keep two things in mind:

1. The ordering needs to be follow, IE then other browsers.

2. The reference link syntax is different for filter and normal CSS. It follows the Javascript Style

May 15, 2008 , Thursday Posted by maxi326 | Web | , , , , | No Comments Yet