reading-notes

Reading notes for Code Fellows!


Project maintained by William-Moreno Hosted on GitHub Pages — Theme by mattgraham

Styling with CSS


The Basics

Imagine there is a box around every HTML element on a webpage. CSS controls the way each of those boxes is presented on the page. CSS associates style rules with HTML elements. Rules are structured as follows:

h1 {color: red;}

This rule changes to color of ‘heading 1’ text to red.

Internal CSS versus External CSS

CSS can be internal or external (sometimes even both) to the HTML document. However, the vastly preferred method is external.

Common CSS Selectors

Selector Type Matched Target Example
universal all elements on page *
type element names h1, p, article
class elements with specified class attribute .class
ID elements with specified id attribute #id
descendant elements which are descendants of another element li>a

CSS Rules Cascade

A hierarcy exists to govern application of conflicting CSS rules for the same targeted element.

Inheritance

Some CSS properties are inherited and others are uninherited. Inherited rules apply to the child elements of an element.

Quirks

Different operating systems and browsers (especially older or less-used ones) can cause your page styling to differ from what you planned. When this happens, it’s often called a “CSS Bug” or a “browser quirk”.

Colors

When selecting colors for an element, they can be specified in several ways. However, the three most common are:

Colors can be apply to different things.

The color property sets the color of foreground items such as text. The background-color property sets the color of the background of a particular element.

Contrast

It is important to select text and background colors that provide enough contrast to be legible.

Opacity

Using color indicators like rgba or hsla, allows you to specify the opacity of a color. The “a” position is a value between 0.0 and 1.0 that represents a percentage of transparency. Some browsers may not support opacity so it is good practice to create an alternate backup CSS rule above the rule that those browsers can use.

Back to Main