CSS Hacks

This section contains css codes and other related material.

CSS Hacks

Postby Web Guru on May 13th, 2008, 11:10 am

The following CSS selectors are considered workarounds and hacks for specific web browsers.

Code: Select all
[b]IE 6 and below[/b]
* html {}

[b]IE 7 and below[/b]
*:first-child+html {} * html {}

[b]IE 7 only[/b]
*:first-child+html {}

[b]IE 7 and modern browsers only[/b]
html>body {}

[b]Modern browsers only (not IE 7)[/b]
html>/**/body {}

[b]Recent Opera versions 9 and below[/b]
html:first-child {}


Usage
If you want to add 5px padding to a div element called #comments specifically for IE 7, then you can use the following hack:

Code: Select all
*:first-child+html #comments
{
  padding: 5px;
}


But if you want to apply the padding just for IE 6, then the following will do the trick:
Code: Select all
* html #comments
{
  padding: 5px;
}


Note that CSS Hacks are not recommended due to their dependence on browser bugs and therefore they should only be used as the last resort.
User avatar
Web Guru
 
Posts: 68
Joined: March 24th, 2008, 7:59 am
Location: Lahore, Pakistan

CSS Hacks for Safari Browser

Postby MT Shahzad on June 12th, 2008, 8:22 am

There are few different hacks available for the safari browser. If you want some specific style just for the safari browser, you can use these css hacks in your project.

Method # 1
Write your safari specific css in the following css declaration, they will be ignored by all other browsers .

Code: Select all
@media screen and (-webkit-min-device-pixel-ratio:0)
{
  b
  {
    font-weight : normal;
  }
}


Method # 2
If your style element contains a # sign in the curly braces, safari will not render that style. Example:

Code: Select all
SAFARI ONLY
.box { margin-top: 5px; }

IE6/IE7/Firefox
.box { margin-top: 15px; #}
MT Shahzad
Web/Software Developer
http://mts.sw3solutions.com
User avatar
MT Shahzad
Site Admin
 
Posts: 300
Joined: February 29th, 2008, 8:11 am
Location: Muridke, Pakistan


Return to CSS - Cascading Style Sheet

Who is online

Users browsing this forum: No registered users and 0 guests

cron