CSS Hacks

Different browsers has different standards for understating CSS attributes, so some CSS properties are not working in all browsers, the easy way to eliminate this issue to use CSS Hacks. Here are some basic CSS Hacks which we can use in regular development and help us to keep our website look same in all browsers. I get a good help from webdevout.net, W3School, stylizedweb.com to learn about CSS Hacks, I try to list CSS Hacks as much as I know, please let me know if anything is missing or wrong in that. Here i am listing about Conditions in CSS, !important, @import, Abstract (*) Hack, Opacity, “min-height” Hack, CSS Reset Hacks.

Conditions in CSS

The most beneficial aspect of conditional comments is that you are not relying on browser bugs when using them. When you use CSS hacks that rely on browser bugs, you run into the possibility of those bugs being fixed at an unwanted time or other browsers showing the same bugs. Conditional comments only work in browsers that specifically support them and claim to be based on Internet Explorer, which in this case all known browsers are honest about.

  1. Positive
    <!--[if condition]> HTML <![endif]-->
  2. Negative
    <!--[if !condition]><![IGNORE[--><![IGNORE[]]> HTML <!--<![endif]-->

Conditional comments can be used as a CSS hack by including links to stylesheets based on the layout engine. Here is an example of how stylesheets can be separated in this way:

<link href="common.css" rel="stylesheet" type="text/css">
<!--[if IE]> <link href="ie.css" rel="stylesheet" type="text/css"> <![endif]-->
<!--[if lt IE 7]> <link href="ie6.css" rel="stylesheet" type="text/css"> <![endif]-->
<!--[if !lt IE 7]><![IGNORE[--><![IGNORE[]]> <link href="ie7.css" rel="stylesheet" type="text/css"> <!--<![endif]-->
<!--[if !IE]>--> <link href="nonie.css" rel="stylesheet" type="text/css"> <!--<![endif]-->


The !important rule is a way to make your CSS cascade but also have the rules you feel are most crucial always be applied. A rule that has the !important property will always be applied no matter where that rule appears in the CSS document. So if you wanted to make sure that a property always applied, you would add the !important property to the tag.

Internet Explorer 6 and below had a problem with the !important identifier that caused it to be ignored if another declaration of the same property appeared later in the same style declaration block. This can be used to feed Internet Explorer 6 and below special property values that are ignored by other browsers. Internet Explorer 7 fixed this issue.

.div { color: #cc0000 !important; }
div { color: #000000; }


If you’ve ever struggled with Netscape Navigator 4.x, this trick is for you. It all hinges on the fact that NN4.x doesn’t understand what @import means. This is by far the most widely used trick, even though it’s only good for hiding external style sheets.

@import url(http://www.example.org/styles/other-style.css);

Abstract (*) Hack

Abstract used when you want to apply some CSS class especially in ie. here is the way we can use it.

Only for IE6
/* the following rules apply only to IE6 */
* html{}
* html body{}
* html .maindiv{width:500px;}

Only for IE7
/* the following rules apply only to IE7 */
*+html .maindiv{width:800px;}


Opacity is use to create transparent element, This is not yet a CSS standard. However, it works in all modern browsers, and is a part of the W3C CSS 3 recommendation.

<style type="text/css">

width: 500px;
height: 250px;
background: url(test.jpg) repeat;
border: 2px solid black;

width: 400px;
height: 180px;
margin: 30px 50px;
background-color: #ffffff;
border: 1px solid black;
/* for IE */
/* CSS3 standard */
/* for Firefox*/
div.transbox p

margin: 30px 40px;
font-weight: bold;
color: #000000;

<div class="background">
<div class="transbox">
<p>This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.


"min-height" Hack

The min-height property sets the minimum height of an element.

CSS .divcss {
width:auto; !important

HTML <div class="divcss">&nbsp;</div>

CSS Reset

<html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
border:0pt none;
table {
caption, th, td {
blockquote:before, blockquote:after, q:before, q:after {
blockquote, q {
quotes:"" "";
strong {
em {
* {


Comments are closed.