css syntax

Table of Contents

1. style sheet - main.css

style sheet refers to the whole file that make look like this:

.redTitle{
    color: red;
}
.greenTitle{
    color: green;
        }

It contains list of rules.

2. Rule

A rule is a selector + a , which shuld look like this:

.greenTitle{
    color: green;
        }

3. selector

to specify which part of html the following style applies to. matching tag or attribute types of seletors are:

  • tag type, like h2
  • tag/element attributes: names are case-sensitive, start with leetters, include [1-9a-zA-Z_\-]
    id
    #id
    class
    .class
  • peudo-
    peudo-classes
    a:hover
    peudo-element
    a::first-letter
  • combinators selector1 selector2

all selector2 elements that are inside selector2 element; an element whose path suffix with slector1/selector2.

3.1. A table of selectors

Backlinks

css

Cascading Style Sheets is a markup language with

  • basically all label:value pairs
  • a large set of builtin properties, including colours/patterns, position styles, common functionalitis like scroll, image auto resize… Sometimes stuff that should be done with actually functions, but very common so css include them and browsers render them.
  • a few syntax tweaks like classes/inheritance, class in css - class in html…

Author: Linfeng He

Created: 2024-04-03 Wed 20:17