4Oct 2008

IE CSS hack without using any hacks!

Author: Gopal | Filed under: Tutorials, Workshop

A few days back while working for a MAJOR client (sorry, can’t mention their name), I discovered something new (I hope it’s new ) - A pure CSS based image replacement solution for IE. This method is helpful especially to solve the PNG issue in IE6. I know there are many CSS hacks available out there to solve the PNG transparency issue, but this method doesn’t need any hacks!! Interesting isn’t it?

Step-1: Let’s review the HTML part first.

<html>

<head>
<title>ProductiveDreams</title>
<link href=”style.css” rel=”stylesheet” type=”text/css”/>
</head>

<body>
<div class=”bg-image”></div>
</body>

</html>

The following are the images that I’ve used for this tutorial. The image without saturation is a .gif and the colored one is a .png. You may right click and save the image.

PNG Image

Colorful PNG Image

Desaturated GIF Image

Desaturated GIF Image

Step-2: The stylesheet

I included the following code in the stylesheet

body{
background:#000;
text-align:center;
}

div.bg-image{
background:transparent url(images/pd.png) no-repeat center !important;
width:134px;
height:134px;
}

Let me walk you through the CSS. The first part simply applies a background color to the body and center aligns the div element. In the second part, I’ve specified the width and height of the div (134px) based on the image dimensions and have given the .png as the background image. Everything works fine?

Step-3: Solution for IE

This the most interesting part that does the magic.

I added another line of CSS code just below
background:transparent url(images/pd.png) no-repeat center !important;
and the following is the code
background-image:url(images/pd.gif);

Check out the result in IE! Awesome…. isn’t it? In all other browsers except IE you will see the colorful png image.

Consolidating the entire thing

So. the final css would look like:

body{
background:#000;
text-align:center;
}

div.bg-image{
background:transparent url(images/pd.png) no-repeat center !important;
background-image:url(images/pd.gif);
width:134px;
height:134px;
margin:0px auto;
}

For your ease, I have attached the sample files as a zip. Feel free to download it :) and do let me know your feedbacks.

Download CSS Solution for image replacement

Downloaded a total of 641 times

23Sep 2008

Min-width issue in IE6

Author: Gopal | Filed under: Quick Tips, Tutorials, Workshop

This is something for those who care for IE6 and not W3C Standards. Recently I worked on a project, for which the layout was liquid and one of the requirements was to use a minimum width of 1000px. Is that a problem? Not at all.

The problem was to make it compatible on all major browsers, including IE6 !!!!!. I wonder why people still use IE.

As usual, I started searching for the solution on the right top of my Firefox window (yes, google!) and found a few websites which had discussions on the same topic. Most of them had lengthy posts and not the real solution. After going through a couple of sites, I concluded with the following solution. I hope this would help those who come across the same problem.

width: expression(document.body.clientWidth < 1002? “1000px” : “auto”);

Just add the above line in your CSS. Replace 1000px with the min-width value and replace 1002 with a value slightly greater than the min-width. To define the mx-width, just replace the “<” with “>”.

Known Issues:

  • Only works JavaScript enabled browsers
  • Not W3C valid

That’s all! I don’t want this post to be lengthy like the others I went through :)

I'm Gopal, currently working as a Senior WebDeveloper.

Gopal Raju

I'm from Trivandrum, Kerala, the southern part of India, but currently living in Bangalore.I am a MAC user.Technorati Profile

You can catch me on Facebook

View Gopal Raju's profile on LinkedIn

twitter ProductiveDreams

If you are expecting me to give you a long story behind the name of this site, I'm sorry.

This site is just meant to help out the designer/developer community which would of course make them more productive.

Advertising


Recent Comments

Twitter Updates

XHTML Valid! CSS Valid!