Do the best you can until you know better. Then when you know better, do better. – Maya Angelou

Mr. Walker's Classroom Blog

Useful CSS Tips for Beginners

Thanks to the CSS and it’s flexibility, styles can be extract independently away from the codes. Now, with some basic understanding of CSS, even a novice can easily change the style of a website.

Whether you are interested in picking up CSS to create your own website, or merely to tweak your blog’s look and feel a little – it’s always good to start with the fundamentals to gain a stronger foundation. Let’s take a look at some CSS Tips Hongkiat.com thought might be useful for beginners.  Hongkiat is a good resource worth looking at for web designers.  Text is below in the event the article is taken down.

  1. Use reset.css

    When it comes to rendering CSS styles, browsers like Firefox and Internet Explorer have different ways of handling them. reset.css resets all fundamental styles, so you starts with a real blank new stylesheets.

    Here are few commonly used reset.css frameworks – Yahoo Reset CSS, Eric Meyer’s CSS Reset, Tripoli

  2. Use Shorthand CSS

    Shorthand CSS gives you a shorter way of writing your CSS codes, and most important of all – it makes the code clearner and easier to understand.

    Instead of creating CSS like this

    1. .header {
    2. background-color: #fff;
    3. background-image: url(image.gif);
    4. background-repeat: no-repeat;
    5. background-position: top left;
    6. }
    .header {
          background-color: #fff;
          background-image: url(image.gif);
          background-repeat: no-repeat;
          background-position: top left;
        }

    It can be short-handed into the following:

    1. .header {
    2. background: #fff url(image.gif) no-repeat top left
    3. }
    .header {
          background: #fff url(image.gif) no-repeat top left
        }

    MoreIntroduction to CSS Shorthand, Useful CSS shorthand properties

  3. Understanding Class and ID

    These two selectors often confuse beginners. In CSS, class is represented by a dot “.” while id is a hash ‘#”. In a nutshell id is used on style that is unique and don’t repeat itself, class on the other side, can be re-use.

    MoreClass vs. ID | When to use Class, ID | Applying Class and ID together

  4. Power of <li>

    <li> a.k.a link list, is very useful when they are use correctly with <ol> or <ul>, particulary to style a navigation menu.

    MoreTaming Lists, Amazing LI

  5. Forget <table>, try <div>

    One of the greatest advantage of CSS is the use of <div> to achieve total flexibility in terms of styling. <div> are unlike <table>, where contents are ‘locked’ within a <td>’s cell. It’s safe to say most <table> layouts are achievable with the use of <div> and proper styling, well maybe except massive tabular contents.

    MoreTables are dead, Tables Vs. CSS, CSS vs tables

  6. CSS Debugging Tools

    It’s always good to get instant preview of the layout while tweaking the CSS, it helps understanding and debugging CSS styles better. Here are some free CSS debugging tools you can install on your browser: FireFox Web Developer, DOM Inspector, Internet Explorer Developer Toolbar, and Firebug.

  7. Avoid Superfluous Selectors

    Sometimes your CSS declaration can be simpler, meaning if you find yourself coding the following:

      1. ul li { … }
      ul li { ... }
      1. ol li { … }
      ol li { ... }
      1. table tr td { … }
      table tr td { ... }

    They can be shorten down to just

      1. li { … }
      li { ... }
      1. td { … }
      td { ... }

    Explanation: <li> will only exist within <ul> or <ol> and <td> will only be inside <tr> and <table> so there’s really not necessary to re-insert them.

  8. Knowing !important

    Any style marked with !important will be taken into use regardlessly if there’s a overwriting rule below it.

    1. .page { background-color:blue !important; background-color:red;}
    .page {	background-color:blue !important;	background-color:red;}

    In the example above, background-color:blue will be adapted because it’s marked with !important, even when there’s a background-color:red; below it. !important is used in situation where you want to force a style without something overwriting it, however it may not work in Internet Explorer.

  9. Replace Text with Image

    This is commonly practice to replace <h1>title</h1> from a text based title to an image. Here’s how you do it.

    1. h1 {
    2. text-indent:-9999px;
    3. background:url(“title.jpg”) no-repeat;
    4. width:100px;
    5. height:50px;
    6. }
    h1 {
    text-indent:-9999px;
    background:url("title.jpg") no-repeat;
    width:100px;
    height:50px;
    }

    Explanation: text-indent:-9999px; throws your text title off screen, replaced by an image declared by background: {...} with a fixed width and height.

  10. Understand CSS Positioning

    The following article gives you a clear understanding in using CSS positioning – position: {...}

    MoreLearn CSS Positioning in Ten Steps

  11. CSS @import vs <link>

    There are 2 ways to call an external CSS file – respectively using @import and <link>. If you are uncertain which method to use, here’s few articles to help you decide.

    MoreDifference Between @import and link

  12. Designing Forms in CSS

    Web forms can be easily design and customize with CSS. These following articles show you how:

    MoreTable-less form, Form Garden, Styling even more form controls

  13. Get Inspired

    If you are looking around for nicely designed CSS-based website for inspiration, or just simply browsing to find some good UI, here are some CSS showcase site we recommend:

    Need more? Here’s a round up of 74 CSS Galleries.

  14. Rounded Corners in CSS

    This following article gives you an idea how to create cross-browser compatible rounded borders with CSS.

  15. Keep CSS Codes Clean

    If your CSS codes are messy, you are going to end up coding in confusion and having a hard time refereing the previous code. For starters, you can create proper indentation, comment them properly.

    More12 Principles For Keeping Your Code Clean, Format CSS Codes Online

  16. Typography Measurement: px vs em

    Having problem choosing when to use measurement unit px or em? These following articles might give you a better understanding on the typography units.

    MoreUnits of Measurement in CSS, CSS Font size explained, Using Points, Pixels, Ems, or Percentages for CSS Fonts

  17. CSS Browsers Compatibility Table

    We all know each browser has different ways of rendering CSS styles. It’s good to have a reference, a chart or a list that shows the entire CSS compatibility for each browser.

    CSS support table: #1, #2, #3, #4.

  18. Design Multicolumns in CSS

    Having problem getting the left, middle and right column to align properly? Here are some articles that might help:

  19. Get a Free CSS Editors

    Dedicated editors are always better than a notepad. Here are some we recommend:

    More – Simple CSS, Notepad ++, A Style CSS Editor

  20. Understanding Media Types

    There are few media types when you declare CSS with <link>. print, projection and screen are few of the commonly used types. Understanding and using them in proper ways allow better user accessibility. The following article explains how to deal with CSS Media types.

    MoreCSS and Media Types, W3 Media Types, CSS Media Types, CSS2 Media Types


Comments

Leave a Reply