2. Syntax

Every style has the following structure.


selector {
    style: value;
}
  • selector: Indicates which part of the document the style or styles will apply to.
  • style: Name of the style.
  • value: Value of the style.

In the following example we change the typography size on all paragraphs.


p {
    font-size: 3rem;
}

There will be cases with several values or other styles.


p {
    font-size: 3rem;
    border: 1px solid black;
}

comments

They must start with /* and end with */.


/* Table styles */
table {
    /* Adds a left margin of 2.5rem */
    margin-left: 2.5rem;
    /* color: pink */
}

<style> tag

If you want to embed the styles in the HTML document itself, you can do so inside <head> with the <style> tag.

<head>
  <style>

  body {
      color: yellow;
  }

  </style>
</head>

<link> tag

CSS can be linked from an external file. Inside <head> use <link> with the relative path to the file.

<head>
    <link rel="stylesheet" type="text/css" href="css/main.css">
</head>

In the following example we can see a real case of a simple website that uses 2 normalizers.

<head>
    <!-- normalize.css normalizer: Balances the styles across browsers -->
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css">
    <!-- Your CSS -->
    <link rel="stylesheet" type="text/css" href="css/main.css">
</head>

A normalizer is a set of CSS that modifies the general styles to balance the design across all browsers, avoiding visual discrepancies.

Building SPAs with Django and HTML Over the Wire: Learn to build real-time single page applications with Python

Building SPAs with Django and HTML Over the Wire: Learn to build real-time single page applications with Python

The HTML over WebSockets approach simplifies single-page application (SPA) development and lets you bypass learning a JavaScript rendering framework such as React, Vue, or Angular, moving the logic to Python. This web application development book provides you with all the Django tools you need to simplify your developments with real-time results.

Buy the book

Help me keep writing

Every coffee gives me a push toward the next article.

Comments

There are no comments yet.