Results 1 to 7 of 7

Thread: [RESOLVED] Some questions about CSS

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2010
    Posts
    195

    Resolved [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]

  2. #2
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2010
    Posts
    195

    Re: Some questions about CSS

    so it is suggested to use type="text/css" everytime i code in css?

  4. #4
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    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" />

  5. #5
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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.

  6. #6
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Re: Some questions about CSS

    thank you for the correction, i didn't know about this myself before.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Oct 2010
    Posts
    195

    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
  •  



Click Here to Expand Forum to Full Width