Free WordPress Theme

Free WordPress Theme
A blue color 3 coloumn wordpress theme by themetation.com

5 USEFUL CSS TRICKS

+ In CSS on 28 Feb 2008 with 6,699 views

css
As you guys know, I am CSS designer now working under a blog advertising company. Most of the time, I deal with the CSS codes and web design. I found that CSS is a useful tool to beautify your website. However, for those who don’t know CSS, it can be a bit complicated but once you know them well. You can make friends with them but maybe you need to leave your old friend (IE6) first… All right, today I am going to share some of the CSS tricks with you. So, forget about the graphic tutorials before first. Let’s learn something different today.

1. FONT

Usually, we beautify font with several line of codes like this :

1
2
3
4
5
6
7
h3.my {
	font-size: 28px;
	font-weight: bold;
	font-family: "Arial", Helvetica, sans-serif;
	color: #333333;
	line-height: 24px;
}
1
<h3 class="my">Loon Design</h3>

Do you find the code is a bit too messy or too long? Here is my solution for them:

1
2
3
4
h3.my {
	font: 900 160%/240% "Arial", Helvetica, sans-serif;
	color: #333;
}
1
<h3 class="my">Loon Design</h3>

Will this cut down your coding time? The output will be:


Loon Design

    Tips

  • The order of the attributes are font: weight size/line-height family;
  • 400 = normal and 900 for bold

2. Margin and Padding

Wondering what how to differentiate them? You check this site for details. We use margin and padding most of the time when we write up the codes. However, I am not to say the padding problem with IE6 ( seriously, I am having a bad time with IE6 during my work, may post it out later ) here but try to give you some tricks on how to make it in 1 line.

Normally, we code like this, we take margin as example :

1
2
3
4
5
6
.my {
	margin-top: 10px;
        margin-bottom: 20px;
        margin-left: 5px;
        margin-right: 5px;
}

but now we can make it in 1 line like this :

1
2
3
.my {
	margin: 10px 5px 20px 5px;
}

    Tips

  • margin: top right bottom left;
  • or when you have the same margin for the top and bottom, it become like this : margin: 10px 0;
  • while margin: 0 auto; means vertically align.

3. Class and ID

the symbol for class selectors is (.) while id selectors is (#), but what’s the different between them?

    id

  • IDs identify a specific element and therefore must be unique on the page. It can only be used once in a page.
  • We consider that it has the higher level than class. It is more specific.
  • can be used and an anchor name.

    Class

  • Classes mark elements as members of a group and can be used multiple times.

Actually, you can use both id and class in a div or element. It’s priority of attributes are depend on id first.

4. Ignore by IE - !important

This is a trick to write something that ignore by IE but can be run in all browsers. The attributes before the !important will be ignored by IE.

1
Example: margin: 20px !important; margin: 10px;

There will be 20px margin for all browsers except IE which will have the 10px margin. This is useful when you doing some positioning adjustments and most of the time it is showing different result in IE browser.

5. Block vs. inline level elements

Most of the HTML elements are block or inline elements. What is the different between them?

    Block

  • Always begin on a new line.
  • Height, line-height and top and bottom margins can be manipulated.
  • Width defaults to 100% of their containing element, unless a width is specified.
  • Example <div>, <p>, <h1>, <form>, <ul> and <li>

    Inline Elements

  • Always begin on the same line.
  • Height, line-height and top and bottom margins can’t be changed.
  • Width is as long as the text/image and can’t be manipulated.
  • Example <span>, <a>, <label>, <input>, <img>, <strong> and <em>

Conclusion

Well, that’s all I wish to share with you guys. Feel free to drop me a message if you find any question about the provided tricks. Thanks!

Similar Contents

Leave a comment now

Comments' Pages: 3 2 1 » Show All

  1. Gravatar
    css lessons
    28 Jun 2008
    22

    css Font examples , Properties , Attribute - - //
    http://www.css-lessons.ucoz.com/font-css-examples.htm

  2. Gravatar
    Amit
    10 Jun 2008
    21

    sir,
    i am new learner for css please give me details of the css

  3. Gravatar
    kailoon
    21 May 2008
    20

    Hi Anand, actually, you can use it within HTML, means that you already can handle it. What you need to do is start using div to replace table.

    CSS is useful when you need a style to be used multiple times for a site in same/different pages. Keep in mind, you are dealing with boxes (div) when building a site. That’s all I can advise :)

    lastly, practices make perfect!

  4. Gravatar
    Anand
    20 May 2008
    19

    Dear Sir

    I just go through the tips which you have mentioned. I am fresher to make css layout kindly suggest me how to start this thing. Actually I know css because of I use in html page. But Still I am not able to make a full css layout

    Kinldy tell me should I do to be proficiene in css layout

  5. Gravatar
    kailoon
    20 Apr 2008
    18

    xaer8 :
    Ya, Practices make perfects! :)

    Madmann :
    Thanks!

  6. Gravatar
    Madmann
    19 Apr 2008
    17

    Very good tut! Bookmarked! ;)

  7. Gravatar
    xaer8
    19 Apr 2008
    16

    Whatever it is, try to test html and css code yourself. You will know the difference. I recommend Adobe Dreamweaver the best or NVU which can be obtain for free. Use examples from available tutorials or tutorials from http://css.maxdesign.com.au/index.htm .

  8. Gravatar
    kailoon
    19 Apr 2008
    15

    omg, now is condom already :o

  9. Gravatar
    sandersky
    19 Apr 2008
    14

    html is like a pclear condom while css is a green glow in the dark coating. it makes the condom a lot more attractive and less plain. lol

Comments' Pages: 3 2 1 » Show All

More Web Design News