treehouse : what would you like to learn today?
Web Design Web Development iOS Development

How better to use?

  • Which example better?

    First Example:

    text-h {
          text-decoration: none;
    }
    
     text-h2 {
          text-decoration: none;
          font-size: 15px;
    }
    

    Second example

     text-h, text-h2 {
          text-decoration: none;
    }
    
     text-h2 {
           font-size: 15px;
     }
    
  • 2nd example...if only because it has a smaller file size.

  • I agree. 2nd example is better. I had always done it the first way for a long time. But as I've gained experience, I have come to like the second approach. If you have a lot of styles that overlap, that approach really saves not only space but makes changes a lot easier.

  • What I usually do is write my code in the way I want each class or ID styled. When I'm finished I'll go back through and combine the similarities between classes or ID's (show in example 2).

  • thanks for comment :)

  • @ChristopherBurton: why don't you do that the first time?

    Ontopic: second approach

  • @Vermaas It's just the way I work. No particular reason.

  • One more example:

    Which example better?

    First-example:

    background {
        background: url("blabla.png") no-repeat;
    }
    

    Second-example:

    background {
        background-image: url("blabla.png");
        background-repeat: no-repeat;
    }
    
  • Either works.

    I tend to use the first option for single background images.

    If I have multiple bg images then I find it somewhat easier to comma separate onto individual lines and each property.

      background {
          background-image: 
          url("blabla.png")'
          url("blafoor.png");
    
      background-repeat: 
          no-repeat,
          repeat;
      }