top
14
02
2008
11:56 am
filed as: CSS, Hacks
author: Dejan Cancarevic
comments: Subscribe
132 Responses
Subversion hosting for web developers

If you are front end coder you must know how important is to make cross browses, valid CSS and xHTML code. And also you must know how much time we are spending in all those hacks and fixes for various browsers. I’ve written about some of them earlier on PNG transparency issues, Yellow fields in web form, Vertical align div etc..

Here is the list of 10 hand picked CSS hacks and tricks which can help you in your CSS code and also save some time.

1. Vertical align div

http://stylizedweb.com/2008/02/01/vertical-align-div/

2. Min-Height

selector {
min-height:500px;
height:auto; !important
height:500px;
}

3. PNG transparency

http://stylizedweb.com/2007/12/30/png-transparency-issues/

4. Autoclear

.container:after {
content: “.”;
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.container {display: inline-table;}
/* Hides from IE-mac \*/
* html .container {height: 1%;}
.container {display: block;}
/* End hide from IE-mac */

5. Reset CSS

body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,
fieldset,input,p,blockquote,th,td {
margin:0; padding:0;
}
table {border-collapse:collapse;border-spacing:0;}
fieldset,img {border:0;}
address,caption,cite,code,dfn,em,strong,th,var {
font-style:normal;font-weight:normal;
}
ol,ul {list-style:none;}
caption,th {text-align:left;}
h1,h2,h3,h4,h5,h6 {font-size:100%;}
q:before,q:after {content:”;}

6. Scrolling Render IE

html {
background : url(null) fixed no-repeat;
}

7. Opacity

#transdiv {
filter:alpha(opacity=75);
-moz-opacity:.75;
opacity:.75;
}

8. PRE Tag

pre {
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
}

9. Li Background Repeat IE

<!–[if lt IE 7]>
<style>
#leftnav li { zoom: 1;} /* haslayout=true */
</style>
<![endif]–>

10. Good to know

@charset “UTF-8″;

/* ———————————————————————-
WinIE7
———————————————————————- */
*:first-child+html selector{property:value;}

/* ———————————————————————-
WinIE6 & Mac IE
———————————————————————- */
* html selector{property:value;}

/* ———————————————————————-
WinIE6
———————————————————————- */
/*\*/
* html selector{property:value;}
/**/

/* ———————————————————————-
MacIE
———————————————————————- */
/*\*//*/
selector{property:value;}
/**/

Subscribe full RSS RSS
  • del.icio.us del.icio.us (0)
  • StumbleUpon StumbleUpon
  • Digg Digg
  • Mister Wong Wong it
132 Responses, Leave a Reply
132
xXKronosXx
May 9th
2008
13:40 pm

Thank’s a lot for these CSS hacks. It’s fantastic to see again and again what you can do just with CSS.

131
cep program
May 5th
2008
16:05 pm

thank you nice sharing

130
Dejan
May 3rd
2008
21:58 pm

Sorry about those spam comments i was away and i have deleted them now, it’s very annoying i know.
Tobias, well i personally don’t like typing captcha over and over again so i’ll leave it like this for now ;)
and of course thanks for the good words everyone :D

129
Zoe
May 2nd
2008
10:09 am

Superb list! It is amazing what you can find on Google!

128
Tobias
May 2nd
2008
2:39 am

Great CSS tips - I’ve actually just used the 2. Min-Height one, which is why I got to this page through Google.

Looks like you have some form spam going on too… :( should add yourself a Captcha on the form :)

127
Ivan
May 1st
2008
8:08 am

Very helpful tips here. But maybe you should moderate your comments to stop the idiots like “hi webmaster” polluting your website comments and thus making them more difficult to read for real people then they ought to be?

126
SERVICES
April 23rd
2008
11:49 am

Great thread! , i like these tips, its looks that i knew just small part of it.

125
Widgets
April 21st
2008
3:08 am

This is very useful!

124
Shane
April 10th
2008
2:55 am

Great tips, thank you !

123
Stronghold
March 28th
2008
23:13 pm

Great tips, i found all information i was looking for, i will use some of them.

122
Daniel
March 27th
2008
5:58 am

I couldn’t understand some parts of this article nnial 2007 - salvatore iaconesi - del.icio.us poetry, but I guess I just need to check some more resources regarding this, because it sounds interesting.

121
Dejan
March 26th
2008
14:23 pm

Ralph
You are welcome ;)

120
Ralph
March 26th
2008
14:19 pm

@Dejan: Thank you for your tip and i read your article with my rss-reader ;)

Amazing… how much comments get on your article… respect.

Ralph

119
stronghold
March 25th
2008
23:11 pm

very useful information :)

118
Jeremy Smith
March 20th
2008
3:57 am

This is very useful!

117
Welcome to Paradise
March 18th
2008
8:47 am

CSS always rocks for me and this article is also not an exception

116
Dejan
March 15th
2008
23:36 pm

@ Ralph
Actually i was thinking about doing that ;)
But until then latest post about CSS tips, tricks
http://stylizedweb.com/2008/03/12/most-used-css-tricks/

115
Ralph
March 15th
2008
23:26 pm

Do you create part two of this Css Hacks ;)

114
JanB
March 9th
2008
0:37 am

Thanks so much! I knew most of them but others not. For example opacity - that’s so cool I’m using it on almost every website im creating but used to insert a second hover image.

113
Yiwu
March 8th
2008
15:30 pm

So good hacks..LOL..

112
Dejan
March 6th
2008
14:08 pm

@ Bryan Miller
I personally don’t use IE5.5 for testing, you could use browser shots for that, and i have used that same code on my
http://stylizedweb.com/2007/12/30/png-transparency-issues/
article ;)

@ Schoolsonweb
thanks, i appreciate it

111
Schoolsonweb
March 6th
2008
6:38 am

Some hacks are really great !!!!!!!! Thanx buddy nice work and knowledge you shared here with us.

110
Bryan Miller
March 6th
2008
4:48 am

Transparent png support for IE 6, works very well.

- Usage -
* html - isolates IE6 (5.5?) browser
Always use a direct path to the image file.
Position content inside of the using the “position:relative;” css property.

- The Code -
* html #transparant-background { height:1%; background:none; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader (src='namepng',sizingMethod='scale', enabled='true' ); }

Have not tested in IE 5.5, please let me know how it goes.

109
atom
March 4th
2008
3:27 am

If you are front end coder you must know how important is to make cross browses, valid CSS and xHTML code.

7, 8, and 9 are not valid. :-\

108
terry
March 3rd
2008
21:26 pm

Great list and definitely worth a bookmark.

107
kerberoS
February 26th
2008
18:25 pm

@You’re welcome Dejan. Im using Google Syntax Highlighter for display my code.

106
LifeStyle
February 25th
2008
15:41 pm

A lot of thanks! Very intresting post!

105
Dejan
February 24th
2008
9:31 am

@ Paul
Yes, of course, go Google min height and you will see same code everywhere

104
Paul
February 24th
2008
8:11 am

On No.2 with !important being outside the semicolon, I’m pretty sure that would do absolutely nothing! Have you for sure verified that this is useful?

103
PraP
February 21st
2008
16:22 pm

Really Handy . Thanks for sharing this.

102
Dejan
February 21st
2008
10:22 am

@ Ross Bruniges
Great, thanks for sharing

so another hack
zoom= 1;

101
almog, media
February 21st
2008
9:33 am

great post thanks for the info

100
Ross Bruniges
February 21st
2008
9:18 am

@dejan

basically zoom:1 will trigger ‘hasLayout’ on any element ie IE (and therefore fix about 80% of the weird IE layout bugs.

It will invalidate your CSS as it’s a proprietary technique (created by Microsoft) but if it’s in an IE CSS file then who really cares ;>

99
mark
February 20th
2008
22:47 pm

@Dejan : Ok, thanks. I’ll check back again.

98
Dejan
February 20th
2008
20:12 pm

@ Mark
I accept the critic. Since i do lot of CSS coding i can see what’s the code for, but i guess it’s not really clear to people who are not really into CSS

http://stylizedweb.com/2008/02/14/10-best-css-hacks/#comment-327

97
mark
February 20th
2008
19:43 pm

You should put some demos out for the codes. It will help people remember if it was an issue for them :)

96
Daniel Marino
February 20th
2008
17:45 pm

On #5, Resetting CSS, instead of specifying:

body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,
fieldset,input,p,blockquote,th,td {
margin:0; padding:0;
}

why not just use:

* { margin: 0; padding: 0; }

95
Dejan
February 20th
2008
13:16 pm

@ Ross Bruniges
I don’t think I’m familiar with it, can you post it here?

94
Ross Bruniges
February 20th
2008
13:11 pm

You missed out what surely is the best hack ever - zoom: 1. Triggers IE when needed and won’t cause any problems to exisiting styles :>

It’s literally been a life saver on more projects than I can think of!

93
Alex
February 20th
2008
10:56 am

I thought that the -moz property aren´t necessary today

92
Dejan
February 19th
2008
22:44 pm

@ Andrej
Unfortunately i haven’t had a chance to test it more, i was concentrating on my writing lately

But as i said, it is very good idea and i hope next versions will be better, and if you would like to make an update on that article or write a guess post you are welcome :)

91
andrej
February 19th
2008
21:05 pm

@ Dejan: So, what is your last take on the issue? Did you have any chance to test the google ie7 javascript some more?

When on my on testing server I did not have any of the problems described in your other post…

Maybe you could do an update on that?

thx :)

90
Dejan
February 19th
2008
19:11 pm

@ All
Thanks for the good words, i appreciate it

@ Andrej
I have written about it here
http://stylizedweb.com/2008/01/11/ie7-javascript-library-review/

89
Dwayne Charrington
February 19th
2008
17:02 pm

Nice extensive list there. Seems like you’ve got the most useful and best CSS hacks listed there.

- Dwayne Charrington.
http://www.dwaynecharrington.com

88
Sarah
February 19th
2008
15:56 pm

Great list. Keep it up!

87
andrej
February 19th
2008
15:23 pm

There is a great javascript-solution for most ie-Hacks and png-transparency:

http://code.google.com/p/ie7-js/

86
Dejan
February 18th
2008
20:29 pm

@ Corey & Fiona
Thanks for the critic, well i have used them before and they are all clear to me this way, but as you are saying people who didn’t have to deal with some of them it can seam confusing a bit

I will try to update it with some screen shots or mention them in later articles

85
Corey
February 18th
2008
17:29 pm

Awesome list! Would it be possible for you to post examples of each of these? I’d like to see them in action, like what the problem looks like and what the fix looks like.

Anyways, just a thought.

Thanks!

84
Fiona
February 18th
2008
14:01 pm

I think links to other articles explaining the hack and the problem in more details would be very useful.

83
Gyorgy Fekete
February 18th
2008
9:41 am

You made me your subscribe with this post. Good job! Keep up the good posts

82
Paranaque
February 18th
2008
9:23 am

great post. i liked it…

81
armando
February 18th
2008
8:39 am

i guess you miss one css hack, Tantec hacks.
btw, nice article.. saved this on my bookmark. :)

80
Dejan
February 16th
2008
21:35 pm

@ All
You are welcome, I’m glad you liked it

79
Ralph
February 16th
2008
21:33 pm

Thank you for this list about CSS Hacks. The link is saved already in my bookmarks ;)

From germany

Ralph

78
Dito
February 16th
2008
5:27 am

Some cool hacks i will use. thanks

77
blacque
February 16th
2008
2:52 am

wow.. i love your article. thanks! :)

76
Marko
February 16th
2008
1:20 am

good list, thank you

75
Dejan
February 15th
2008
10:35 am

@ Jermayn Parker
That’s the good one too
For the selector try http://www.w3.org/TR/REC-CSS2/selector.html

@ Floral
here it is more explained http://www.stopdesign.com/examples/ie5mac-bpf/

74
floral
February 15th
2008
4:11 am

mac IE is * html>body

73
floral
February 15th
2008
4:11 am

MacIE
——————————————————–
* html>body
——————————————————–

72
Jermayn Parker
February 15th
2008
2:06 am

In response to your min-height hack I personally use a different hack
http://germworks.net/blog/2007/01/31/width-ie-hack/

What does the ’selector’ do?

71
Dejan
February 14th
2008
18:23 pm

@ Barney
Thanks for typo and js error, will be fixed
and also thanks for the good words i appreciate it ;)

About no 6, this fixes a very annoying bug in IE by where when you scroll the page becomes corrupted. It relates to the way IE renders pages. This code places a null background image behind, making IE render the page differently.

This can also be place on the body tag unless it already has a background.

70
Brian Purkiss
February 14th
2008
16:42 pm

Agreed, very nice list.
I’ve been interested in learning how to do the opacity… but never got around to it.

Thanks!

69
Barney
February 14th
2008
14:10 pm

Just realised how overly critical and nasty that post seemed! I might add I discovered your blog last week and it’s at the top of my RSS list right now. Tastefully grungy, unpretentiously clean design = great starting point for any content. Quickly summarised, useful, & professional guides = great blog content.

PS: gravatar is giving me a javascript error every time I enter a character in this form:

hex_md5 is not defined
updateLivePreview()stylizedweb.com (line 106)
[Break on this error] gravatar = ‘http://www.gravatar.com/avatar.php?gravatar_id=’ + hex_md5(eml) + …

68
Barney
February 14th
2008
14:06 pm

Typo: 1. Vertical aling

What’s this?
6. Scrolling Render IE

7. Opacity — Mozilla doesn’t need the proprietary -moz property anymore. It was the first agent to support the untweaked ‘opacity:’ as I remember.

67
Ivan Nikolic
February 14th
2008
13:25 pm

Nice list, thanks.

66
3kolone
February 14th
2008
13:10 pm

Great list … never mind the order ;-) … bookmark!

65
John
February 14th
2008
12:11 pm

good list, i just don’t like the order..

64 Trackback(s)
  1. May 6, 2008: SEO & Web Design » Blog Archive » Watch out: Web Designer’s Awesomeness in February
  2. Apr 21, 2008: Yararlı Bilgiler » Links for 2008-04-18 [del.icio.us]
  3. Apr 20, 2008: Rss VURSAKnoktacom » Blog Arşivi » Links for 2008-04-18 [del.icio.us]
  4. Apr 9, 2008: CSS tricks and tips | Website Ideas
  5. Mar 29, 2008: Most used CSS tricks
  6. Mar 28, 2008: PHP MYSQL HP-UX CSS AJAX : iNetVista
  7. Mar 26, 2008: CCS & Ajax Links for March 24th | False Positives
  8. Mar 19, 2008: Most used CSS tricks « Share4Vn.com Blog
  9. Mar 19, 2008: Most used CSS tricks « IT Pearls
  10. Mar 17, 2008: The essential list of CSS tips, tricks & hacks | Jayhan Loves Design & Japan
  11. Mar 13, 2008: diarioTHC | Los trucos CSS más usados
  12. Mar 12, 2008: Most used CSS tricks | StylizedWeb.com
  13. Mar 9, 2008: 10 hacks CSS para que nuestras páginas se vean bien en varios navegadores | ChristianGL.CoM
  14. Mar 8, 2008: Fatih Hayrioğlu’nun not defteri » 08 Mart 2008 web’den seçme haberler
  15. Mar 7, 2008: Wochenendbeilage #19 | REDUXO
  16. Mar 6, 2008: Urls Sinistras » del.icio.us entre 18/02/2008 e 05/03/2008
  17. Mar 4, 2008: Ragheb Alama
  18. Mar 3, 2008: Stylize Web 10 Best Cross Browsers CSS Hacks | GreatSo.com
  19. Mar 3, 2008: Recursos y Tutoriales » Blog Archive » 500 links de recursos para diseñadores y desarrolladores web
  20. Mar 2, 2008: Un petite tournante de liens et ressources #1 » Emmanuel de Taillac .fr
  21. Mar 1, 2008: Weekend Links - Best CSS Hacks, Apache Speed Optimization, Ajax File Upload, Image Theft
  22. Mar 1, 2008: StylizedWeb, web trends and tutorials | blog.bouctoubou.com - path ton chemin
  23. Feb 29, 2008: Webcreatives » 10 best CSS hacks | StylizedWeb.com
  24. Feb 29, 2008: Watch out: Web Designer’s Awesomeness in February « outaTiME
  25. Feb 29, 2008: Watch out : Web Designer’s Awesomeness of February
  26. Feb 28, 2008: CSS Ninjitsu Links | dBlogIt by Dustin Boston
  27. Feb 26, 2008: Iconos, hacks CSS y alguna cosa más… -- los chicos de la playa
  28. Feb 26, 2008: Cool Sites I’ve Stumbled Upon | Project Wicked | Buzz
  29. Feb 25, 2008: DimidoBlog » Bloglinks 08/2008
  30. Feb 25, 2008: 10 Best CSS Hacks | dontgetmad
  31. Feb 24, 2008: Templaterie Blog
  32. Feb 24, 2008: Интересный интернет - 24 февраля 2008 | AltBlog.ru
  33. Feb 23, 2008: BlogBuzz February 23, 2008 » Webmaster-Source
  34. Feb 23, 2008: 171 trucchi, tecniche e suggerimenti per lo sviluppo di CSS : cssblog.it
  35. Feb 22, 2008: 10 Användbara CSS Hacks « Webbsajter’s Weblog
  36. Feb 21, 2008: 10 “Best CSS Hacks” | David Bisset: Web Designer, Coder, Wordpress Guru
  37. Feb 21, 2008: Link notes dal 18 2 2008 al 20 2 2008 » Sapientone
  38. Feb 20, 2008: Los 10 mejores trucos para CSS | frogx.three
  39. Feb 20, 2008: Customer Street CSS | 10 Best CSS Hacks And Tricks
  40. Feb 20, 2008: links for 2008-02-20 | Funny Stuff is all around
  41. Feb 20, 2008: links for 2008-02-19 « toonz
  42. Feb 19, 2008: blog of matthew moore » 10 Best CSS Hacks
  43. Feb 19, 2008: » I 10 migliori hack per CSS | DoZ-log |
  44. Feb 19, 2008: digitalhexagon.com » Blog Archive » 10 Best CSS hacks
  45. Feb 19, 2008: links for 2008-02-19 « Ramblings of an Eccentric Soul…
  46. Feb 19, 2008: Thiemo Gillissen » 10 best CSS Hacks
  47. Feb 19, 2008: sabel’s blog » Archiv » Die 10 besten CSS-Hacks
  48. Feb 19, 2008: iLibrarian » Top Ten Top Lists Roundup
  49. Feb 19, 2008: hype.yeebase.com
  50. Feb 19, 2008: Max Design - standards based web design, development and training » Some links for light reading (19/2/08)
  51. Feb 19, 2008: » CSS Hacks — cne _LOG Archiv
  52. Feb 19, 2008: links for 2008-02-19 « Bob’s Weblog
  53. Feb 19, 2008: F-LOG-GE » Blog Archive » 10 nützliche CSS-Hacks
  54. Feb 19, 2008: » links for 2008-02-19
  55. Feb 19, 2008: perryboy.com » Blog Archive » Daily Links
  56. Feb 18, 2008: Web 2.0 Announcer
  57. Feb 18, 2008: Gilbert "Gilbitron" Pellegrom | 10 Best CSS Hacks
  58. Feb 18, 2008: www.webeame.net
  59. Feb 18, 2008: Faydalı 10 CSS Yöntemi - Göstergeç.net
  60. Feb 18, 2008: Los 10 mejores hacks de CSS | unblogged. A blog about nothing. Yeah, nothing
  61. Feb 18, 2008: Web 2.0 Announcer
  62. Feb 18, 2008: 10 best CSS hacks
  63. Feb 15, 2008: Swerdloff » links for 2008-02-15
  64. Feb 14, 2008: purrl.net |** urls that purr **|
What do you think?

Name (required)

Email (will not be published) (required)

Website

About

StylizedWeb is blog about web trends and tutorials and KnowHow community forum designed and maintained by Dejan Cancarevic.

Six Shooter Media
logo and web site design

Search