css - What does "<html xmlns="http://www.w3.org/1999/xhtml">" do? -


this question has answer here:

i can't believe happening in website. when add line:

<html xmlns="http://www.w3.org/1999/xhtml"> <!doctype html> <html>  <head> 

everything works fine. , when don't, css "messes" up, becomes different , layout becomes "ugly".

how can line solve problems?!

you're mixing html xhtml.

usually <!doctype> declaration used distinguish between versions of htmlish lanaguages (in case, html or xhtml).

different markup languages behave differently. favorite example height:100%. @ following in browser:

xhtml

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head>   <style type="text/css">     table { height:100%;background:yellow; }   </style> </head> <body>   <table>     <tbody>       <tr><td>how tall this?</td></tr>     </tbody>   </table> </body> </html> 

... , compare following: (note conspicuous lack of <!doctype> declaration)

html (quirks mode)

<html> <head>   <style type="text/css">     table { height:100%;background:yellow; }   </style> </head> <body>   <table>     <tbody>       <tr><td>how tall this?</td></tr>     </tbody>   </table> </body> </html> 

you'll notice height of table drastically different, , difference between 2 documents type of markup!

that's nice... now, <html xmlns="http://www.w3.org/1999/xhtml"> do?

that doesn't answer question though. technically, xmlns attribute used root element of xhtml document: (according wikipedia)

the root element of xhtml document must html, , must contain xmlns attribute associate xhtml namespace.

you see, it's important understand xhtml isn't html xml - different creature. (ok, kind of different creature) xmlns attribute 1 of things document needs valid xml. why? because working on standard said ;) (you can read more xml namespaces on wikipedia i'm omitting info 'cause it's not relevant question!)

but why <html xmlns="http://www.w3.org/1999/xhtml"> fixing css?

if structuring document so... (as suggest in your comment)

<html xmlns="http://www.w3.org/1999/xhtml"> <!doctype html> <html> <head> [...] 

... fixing document, leads me believe don't know css , html (no offense!) , truth without <html xmlns="http://www.w3.org/1999/xhtml"> it's behaving , with <html xmlns="http://www.w3.org/1999/xhtml"> it's not - , think is, because you're used writing invalid html , working in quirks mode.

the above example provided example of same problem; people think height:100% should result in height of <table> being whole window, , doctype breaking css... that's not case; rather, don't understand need add html, body { height:100%; } css rule achieve desired effect.


Comments