CSS megjegyzések


Tartalomjegyzék

    Tartalomjegyzék megjelenítése


A CSS megjegyzések nem jelennek meg a böngészőben, de igen segít dokumentálni a forráskódot.


CSS megjegyzések

A megjegyzések a kód magyarázatára szolgálnak, és segíthetnek a forráskód későbbi szerkesztésénél.

A böngészők figyelmen kívül hagyják a megjegyzéseket.

A CSS-megjegyzés a <style> elemen belül található, /* karakterrel kezdődik és */:

Példa

 /* This is a single-line comment */
p
{
   
color: red;
}

Próbálja ki Ön is →

<!DOCTYPE html>
<html>
<head>
<style>
/* This is a single-line comment */
p {
  color: red;
} 
</style>
</head>
<body>

<p>Hello World!</p>
<p>This paragraph is styled with CSS.</p>
<p>CSS comments are not shown in the output.</p>

</body>
</html>


A kódban bárhol hozzáadhat megjegyzéseket:

Példa

   p
{
   
color: red; 
  /* Set text color to red */
}

Próbálja ki Ön is →

<!DOCTYPE html>
<html>
<head>
<style>
p {
  color: red;  /* Set text color to red */
} 
</style>
</head>
<body>

<p>Hello World!</p>
<p>This paragraph is styled with CSS.</p>
<p>CSS comments are not shown in the output.</p>

</body>
</html>


A megjegyzések kiterjedhetnek több sor:

Példa

 /* This is
a multi-line
comment */

p
{
   
color: red;
}

Próbálja ki Ön is →

<!DOCTYPE html>
<html>
<head>
<style>
/* This is
a multi-line
comment */

p {
  color: red;
} 
</style>
</head>
<body>

<p>Hello World!</p>
<p>This paragraph is styled with CSS.</p>
<p>CSS comments are not shown in the output.</p>

</body>
</html>




HTML és CSS megjegyzések

A HTML oktatóanyagból megtudta, hogy megjegyzéseket fűzhet a HTML-forráshoz a > szintaxis.

A következő példában HTML és CSS megjegyzések kombinációját használjuk:

Példa

 <!DOCTYPE html>
<html>
<head>
<style>
p {
  color: red; /* Set 
  text color to red */
} 
</style>
</head>
<body>
<h2>My 
  Heading</h2>
<!-- These paragraphs will be red -->
<p>Hello 
  World!</p>
<p>This paragraph is styled with CSS.</p>
<p>CSS comments are 
  not shown in the output.</p>
</body>
</html>

Próbálja ki Ön is →

<!DOCTYPE html>
<html>
<head>
<style>
p {
  color: red; /* Set text color to red */
}
</style>
</head>
<body>

<h2>My Heading</h2>

<!-- These paragraphs will be red -->
<p>Hello World!</p>
<p>This paragraph is styled with CSS.</p>
<p>HTML and CSS comments are not shown in the output.</p>

</body>
</html>