-
Feb 12th, 2011, 07:26 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Some questions about CSS
1) What is the difference between:
a) <style> .... </style>
b) <style type="text/css"> ... </style>
2) Do i have to use <!-- --> in the css code just like in javascript? [i have seen it also in css]
-
Feb 12th, 2011, 07:33 AM
#2
Fanatic Member
Re: Some questions about CSS
#1
the only difference is that you tell the browser what is inside of the <style></style> tag, and of course, if you don't include type="text/css" i don't think a html validator would accept it, because the attribute is required.
#2 personally i don't know the answer so maybe this could help a bit:
http://lachy.id.au/log/2005/05/script-comments
-
Feb 12th, 2011, 07:35 AM
#3
Thread Starter
Addicted Member
Re: Some questions about CSS
so it is suggested to use type="text/css" everytime i code in css?
-
Feb 12th, 2011, 07:42 AM
#4
Fanatic Member
Re: Some questions about CSS
only if you want the code to be valid and you can also use meta tag to include a css file
Code:
<link href="/layout.css" rel="Stylesheet" type="text/css" />
-
Feb 12th, 2011, 07:57 AM
#5
Re: Some questions about CSS
2) no, you do not have to use HTML comments (<!-- -->). They were used back in the day to hide CSS from browsers that didn't know what CSS is. Today finding such a browser is a big task, so you don't need to have the comments there.
XHTML is a bit different though! Contents of style & script elements have been defined in such a way that content needs to be defined as CDATA and commented. Atleast if you don't want a validator to complain about non-XML contents. To do this:
Code:
<style type="text/css">/*<![CDATA[*/
CSS HERE
/*]]>*/</style>
Code:
<script type="text/javascript">/*<![CDATA[*/
JAVASCRIPT HERE
/*]]>*/</script>
Basically this works so that XML CDATA definition prevents complaints about CSS or JavaScript code being invalid XHTML, while CSS & JavaScript comments (/* comment */) prevent the CDATA part being parsed as CSS or JavaScript code.
Ugly, but it does the job. You don't have this problem if you use external CSS and JavaScript files, as stated by Justa Lol.
-
Feb 12th, 2011, 07:58 AM
#6
Fanatic Member
Re: Some questions about CSS
thank you for the correction, i didn't know about this myself before.
-
Feb 13th, 2011, 10:38 AM
#7
Thread Starter
Addicted Member
Re: Some questions about CSS
thank you all for the information
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|