CSS Guide Part 3 – Everything You Need To Know About Selectors, Properties and Values

Posted by TotalDC

Selectors are the names given to styles in internal and external CSS. For each selector there are properties written inside curly brackets like – color, font-size or background-color.

A value is given to the property after the colon and then semi-colons are used at the end to separate the properties. Like that:

body {
    font-size: 14px;
    color: lightgrey;
}

This will apply the given values to the font-size and color properties of body selector.

Length and Percentage

There are many specific units for values used in CSS, but there are some general units that are used by a number of properties and it is worth familiarizing yourself with these before going forward.

  • px  is the unit for pixels.
  • em  is the unit for the calculated size of a font.
  • pt  is the unit for points, for measurements typically in printed media.
  • %  is the unit for percentages.

Other units include pc (picas), cm (centimeters), mm (millimeters) and in (inches).

When a value is zero, you do not need to state a unit. For example, if you wanted to specify no border, it would be border: 0.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: