5 CSS tips & tricks

Pin It


I was searching hacks and tricks on css and found this article which is simple and very useful. I hope this will be informative to others too.

1. Avoid CSS hacks, use future proof method

We should avoid using hacks unless there are no other ways to fix it. Because, we will not able to know when those hacks will stop working. The most common way to tackle with different version of IEs is using the if else statement:

<!--[If IE 5]>
ie 5
< ![endif]-->
 
<!--[If lte 6]>
ie 6 and lower
< ![endif]-->
 
<!--[If gte 7]>
ie 7 or higher
< ![endif]-->

2. Use group selector

Using group selector is a good practise to minimize your coding effort and also save a few bytes out of your style sheet. We can group the selector to avoid repeating declaring the same properties for different elements

h1, h2, h3, h4, h5, h6 {
font-family:arial;
margin:0.5em 0;
padding:0;
}

3. Center elements

It’s easy to center an element, for Firefox and Safari, we only need to specify the width and margin left and right set to auto. However, you will need to specify text-align to center in the parent element for IE.

body {
    text-align:center;  /* for ie   */
}
 
#container {
    width:800px;
    margin:0 auto;
    text-align:left;
}

4. CSS Positioning

This is something I’ve just discovered it few weeks ago. Set the abolute position within a container. #item will appear inside the #container exactly 200px from the left and 50px from the top.

#container {
    position: relative;
    width:500; height:300;
}
 
#item {
    position: absolute;
    left: 200px;
    top: 50px;
}

5. Text transform

This is something I discovered long time ago, CSS has the ability to transform text to lowercase, uppercase and capitalized the first character of a word. w3schools CSS – Text transform

h1 {
    text-transform:uppercase;
}
h2 {
    text-transform:capitalize;
}
p {
    text-transform:lowercase;
}

Please have your say.

1 comment on this postSubmit yours
  1. nice post. thanks.

4 total pingbacks on this post
Submit your comment

Please enter your name

Your name is required

Please enter a valid email address

An email address is required

Please enter your message

Twitter

  • May 2, 2012 04:15

    10 Free WordPress Theme To Make You Forget About Premium Theme http://t.co/YRiLCiVa

  • March 2, 2012 17:16

    3 Helpful Tools to Test Cross Browser Compatibility of Webpage http://t.co/FY0jh8Dn

  • March 2, 2012 16:43

    3 Helpful Tools to Test Cross Browser Compatibility of Webpage http://t.co/QUlYKInf #IE #FF #Chrome #Testing #CrossBrowser

  • March 2, 2012 12:52

    Top 5 Plugins to Build Contact Form for WordPress http://t.co/PWyR08Iq #WordPress #Plugins #ContactForm

  • June 11, 2011 02:49

    CSS 3 Transitions http://bit.ly/m0pK3t

Design Gala © 2012 All Rights Reserved

Designed by 76miles

Powered by WordPress

More in CSS (7 of 15 articles)
calen