Software is like sex... It's better when it's free.

Blog - Tag 'ie6'

It was a good time that I saw in the middle of the css the keyword !important, not really interest me, to finally realize it's a wonderful way to hack IE6, while respecting the standards w3c.

On large web projects, you probably already have encountered problems with css styles that did not apply as you wish before you realize that you applied this style in the wind as it was refined a little further, the overwhelming style 1.

To remedy this, I put up a lot of legacy styles to limit the risk of overload css. The keyword !important is just to prioritize the application of a style to another. Thus if an attribute is defined with the keyword !important at the end of definition and this attribute is redefined below or in an external stylesheet, it will not be overwritten. 

Where it becomes very good with our beloved IE6, eternal daemon in xHTML/CSS implementation, is that this poor browser doesn't support this keyword. What it do ? It ignores at all ! We can therefore, from the time keyword respects standards, take this unknowing to hack IE6 :)

Go ! a little css is more effective than a long speech.

html, body, p, form, fieldset, table, {
  margin:0;
  padding:0;
}
body{
  background-color:#FFF;
  font-family: Verdana, Arial, Helvetica, sans-serif;
  font-size:11px;
}
ol, ul{
  list-style: none;
}
div#fakeDiv{
  display:block;
  width:300px;
  height:300px;
  background-image:url(../Img/test.png) !important; /* non-sucky browser */
  background-image:url(../Img/test.gif); /* IE6 */
  background-repeat:no-repeat;
}

Thus providing a transparent image on high PNG quality on browsers know the keyword !important and less GIF quality on IE6 and below, all without going through <!--[ IF lt IE 7]> or PNG fix.

This example is extensible to any css recurring problem on IE6, including double margin, negative padding, transparency, etc..

Tags:  csshackie6microsoftw3c.
Posted the Tuesday 28 april 2009 22:25:08 - 3 comments

A very useful script for those, like me, who are tired of stylesheets in IE6 only dedicated to problems of transparency in png.

This js script loads only on IE6 (and lower) in this way:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <!--[if lt IE 7]>
      <script defer type="text/javascript" src="Public/Scripts/Javascript/Statics/pngfix.js"></script>
    <![endif]-->
  </head>

It allows, if we affect the attributes html width = "" and height = "" to images in question, to apply transparency on them. The script available on the author website PNG Fix is the following :

var arVersion = navigator.appVersion.split("MSIE");
var version = parseFloat(arVersion[1]);
if ((version >= 5.5) && (document.body.filters))
{
  for(var i=0 ; i<document.images.length ; i++)
  {
    var img = document.images[i];
    var imgName = img.src.toUpperCase();
    if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
    {
      var imgID = (img.id) ? "id='" + img.id + "' " : "";
      var imgClass = (img.className) ? "class='" + img.className + "' " : "";
      var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
      var imgStyle = "display:inline-block;" + img.style.cssText;
      if (img.align == "left") imgStyle = "float:left;" + imgStyle;
      if (img.align == "right") imgStyle = "float:right;" + imgStyle;
      if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
      var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
      img.outerHTML = strNewHTML;
      i = i-1;
    }
  }
}
Tags:  hackie6javascriptmicrosoft.
Posted the Wednesday 29 april 2009 23:54:26 - 1 comment