Styling clean div tags
In stylesheets you often see div#id { /* something */ }
and div.class { /* ... */ }
but how often do yo开发者_开发百科u see just div { /* something */ }
?
Is it a bad idea to style div tags that have no #id or .class associated with them?
It's not necessarily bad practice, as long as you're sure you want to apply this styling to every single div
in your document. You can always override and / or add further down the cascading style sheet.
It all depends on your purpose.
Styling all divs to be one specific style can be overridden.
So you may want to force height on all divs, but on divs with class hidden you want display none. Finally you may want a div with id = hello to have a red background.
Next you decide that you want a div with id=foo and class = bar to be have height:200.
div {
height:100px;
}
div.hidden {
display:none;
}
div#hello {
background-color:#FF0000;
}
div#id.bar {
height:200px;
}
Well...it depends on what you want. If you want every single div tag in your markup to have the same style then it makes sense to do a tag selector instead of a class or id selector.
As you normally use divs for a bunch of different stuff, I would answer "yes".
精彩评论