div.classname in css file

后端 未结 12 676
臣服心动
臣服心动 2020-12-10 02:21

I have seen some developers write

HTML:

some content

CSS:

12条回答
  •  心在旅途
    2020-12-10 02:59

    the style will be applied only when the class is applied to a div ?

    there are some performance implications too.. here is the performance counter

    • IDs are the fastest
    • Tag names are next fastest
    • Class names with no tag name are the slowest

    As for which one to use, use whichever is most appropriate. If you have a search box on your page then using an ID for that would be most appropriate because there's only one search box. Table rows on the other hand will probably be identified by class because there is (or can be) more than one.

    something that most ppl dnt pay attention to is semantics while naming a class.. read this blog for some nice tips: http://css-tricks.com/13423-semantic-class-names/

    Sorry I wanted to add One important thing to remember about how browsers read your CSS selectors, is that they read them from right to left. That means that in the selector ul > li a.home the first thing thing interpreted is a.home so avoid making such mistakes

提交回复
热议问题