CSS cascading rules for html controls -


why css rules not cascade down automatically html controls input or select , style display of text in them?

for ex: have css class applied on body tag renders text in red. due cascading rules, text in html document rendered in red (unless overridden). if have textbox control in document, style not cascade textbox render text in in red.

could point me reference document talks that??

the reason default css styles determined browser.

  • input , select have default colors/sizes/padding etc.
  • most other elements use inherit color , size.
  • another example font-size of table fixed , not inherited default, , must overridden developer.

try example html:

<html>  <style type="text/css"> body { color:red; font-size:36px; } </style>  <body> hello <input type="text" value="test value"/> <table><tr><td>cell value</td></tr></table> </body> </html> 

you see font-size , color not inherited input. also, cell value stayed @ default font size. add following css style block:

input { color:inherit; font-size:inherit; } table { font-size:inherit; } 

you'll see inherit expected now.

what want use reset stylesheet. tables 1 element has default style attached isn't desirable many developers, , every browser might different. why many make use of reset css stylesheets. these stylesheets reset elements uniform sizes , 0 margins, padding, etc. more extreme others. see http://meyerweb.com/eric/tools/css/reset/ or google example.

since reset stylesheets don't make colors of input , select inherit (most developers don't want them inherit , instead want explicitly set size/color), should set them in stylesheet:

input, select { ... } 

be careful * { ... } any purpose (as suggested other answer). breaks "cascading" part of css , cause rules not cascade expect in nested elements. if use * { color:red; } , have following html:

<h1 style="color:green;">hello <i>world</i></h1> 

you end green hello , red world. (because <i> matches *. new element reset style red, , color no longer cascades @ all!)


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -