00 Votes

CSS: Define CSS only for current HTML page

Question by Guest | 2015-04-14 at 22:46

Up to now, I have always included CSS stylesheets via an external file or I have applied the styles directly to the corresponding element.

However, now, I am faced with the situations that I have multiple HTML elements on my page for which I would like to define some central CSS rules. Because those elements are not appearing on any of the page, I do not want to declare them in my general CSS file. Simultaneously, it is inconvenient to repeat the rules for each element again.

Thus, is there any solution between with which I am able to define some CSS rules only for the current page within its head without applying the elements of the page?

ReplyPositiveNegative
0Best Answer0 Votes

Of course, CSS can also be directly defined in the head of an HTML page. Here you can see a small example for the structure.

<!DOCTYPE html>
<html>
<head>
<title>Seitentitel</title>
<link rel="stylesheet" type="text/css" href="style.css">
<style type="text/css">
<!--
h1 { font-size: 14px; padding-bottom: 10px; }
p  { font-size: 10px; }
-->
</style>
</head>
  <body>
    <h1>Überschrift</h1>
    <p>Absatz</p>
  </body>
</html>

As you can see, on the one hand, we have included an external file style.css and on the other hand, we have defined some additional rules within the head.

You can learn more about it in my tutorial about including CSS style sheets.
2015-04-16 at 19:16

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.