Jump to content

Order of Declarations


mr_mars2011

Recommended Posts

Just a quick question I can't seem to find the answer to.I was wondering if there's a specific order that declarations should appear.For Example

div{	  width: 200px;	  font-family: Arial, "MS Trebuchet", sans-serif;	  border-bottom: 2px dotted #000;	  border: 1px solid #999;	  color: red;	  height:200px;}

Does it matter that width comes first then font-family then border? I know there are issues with specificity: border-bottom won't be applied because border will overide it. But does it matter that I have width at the top and height at the bottom? I'm guessing it's a good idea to keep related properties together or use shorthand where possible.Can't help feeling that with the amount of time I've been learning CSS I should probably know the answer to this.

Link to comment
Share on other sites

Does it matter that width comes first then font-family then border?No.I know there are issues with specificity: border-bottom won't be applied because border will overide it.Correct.But does it matter that I have width at the top and height at the bottom?No.I'm guessing it's a good idea to keep related properties together . . .As a matter of developer sanity, correct. E.g., I like to keep all dimension rules together (height, width), all edge-treatment rules together (margin, padding, borders, shadows), and so on.. . . or use shorthand where possible.Maybe. Some shorthand properties must come in a precise sequence and are not always intuitive. (E.g., the font-size/line-height properties of the font rule.) If you write CSS often enough that you instinctively know those sequences, this can be a useful idea. If not, shorthand can lead to enough confusion and consultation of manuals that it's more hassle than convenience.

Link to comment
Share on other sites

Thanks for the updated reply. I new I was along the right lines just needed some reassurance. The info on shorthand properties was useful. Thinking about it I really only use shorthand properties on padding, margin and borders.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...