Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML comments in CSS?

Tags:

css

I was checking out some of Amazon's CSS and noticed they have HTML commented out a chunk of CSS. I know there is conditional formatting for Internet Explorer with HTML comments, but I am viewing this in Chrome. What is the purpose of it?

Oh, I should note that these styles are actually being applied.

<!-- BeginNav -->

<style type="text/css">

    <!--

    .nav-sprite {
      background-image: url(http://g-ecx.images-amazon.com/images/G/01/gno/beacon/BeaconSprite-US-01._V141013396_.png);
    }
    .nav_pop_h {
      background-image: url(http://g-ecx.images-amazon.com/images/G/01/gno/beacon/nav-pop-h._V155853593_.png);
    }
    .nav_pop_v {
      background-image: url(http://g-ecx.images-amazon.com/images/G/01/gno/beacon/nav-pop-v._V155853593_.png);
    }
    .nav_ie6 .nav_pop_h {
      background-image: url(http://g-ecx.images-amazon.com/images/G/01/gno/beacon/nav-pop-8bit-h._V155961234_.png);
    }
    .nav_ie6 .nav_pop_v {
      background-image: url(http://g-ecx.images-amazon.com/images/G/01/gno/beacon/nav-pop-8bit-v._V155961234_.png);
    }
    .nav-ajax-loading .nav-ajax-message {
      background: center center url(http://g-ecx.images-amazon.com/images/G/01/javascripts/lib/popover/images/snake._V192571611_.gif) no-repeat;
    }
    -->

</style>
like image 831
Sackling Avatar asked Mar 21 '12 20:03

Sackling


People also ask

How do I comment in CSS?

The /* */ comment syntax is used for both single and multiline comments. There is no other way to specify comments in external style sheets. However, when using the <style> element, you may use <!

How do you write comments in HTML CSS and Javascript?

To make a single line CSS comment, put the comment text or code between /* */ tags.

What does /* mean in CSS?

This question already has answers here: I know in CSS we use /* */ for comment text .


1 Answers

It's created by someone who thought that visitors of the site use a browser which does not recognise <style> tags.

(Ancient) browsers, which do not recognise <style> tags, will not show "weird" characters (CSS rules) because of the HTML comments.

Most browsers recognise the <style> tag, so the developer seems to use <!-- --> out of (bad) habit. It should not be used.

like image 129
Rob W Avatar answered Nov 16 '22 03:11

Rob W