Sept 1, 2022
Cascading Style Sheets - a stylesheet language that allows us to specify rules that affect the look and feel of HTML documents
Styling options include width, height, borders, colors, typefaces, font size, positioning, etc
CSS rules are associated with elements.
There are two parts to a CSS rule:
p { font-family: Arial; }
Each rule in the declaration is broken into two parts, separated by a colon:
h1, h2, h3 { font-family: Arial;
color: yellow; }
section
<link href=“style.css” type=“text/css” rel=“stylesheet”>
the CSS is included in a style section on the HTML page
<style type=“text/css”>
body {
background-color: black;
color: white; }
</style>
There are many ways to represent a selector
* {}
targets all elements on a page
h1, h2, h3 {}
targets the specified elements
.item {}
targets all elements which have the specified class value
#firstName {}
targets the element with specified id value
li>a {}
targets the right side element (a) if they are children of the left side element (li)
p a {}
targets any <a> element that sit inside <p> even if it is multiple levels deep
There is a priority system in place to determine which rule applies to an element:
Some CSS properties propagate from parent elements to child elements (mostly color/font styles and not block styles)
We can also force inheritance for non-inheriting properties by using the inherit property value:
.page {
border: 1px solid gray;
padding: inherit;
}
CSS can be commented with the following comment style:
/* header 1 color style */
h1 {
color: red;
}
Colors can be specified in CSS in a number of ways:
colors are expressed in how much red, green, and blue are in it
color: rgb(100,100,100);
six digit code that represents how much red, green, and blue are in the color; preceded by a hash sign
color: #008B8B;
a set of color names that browsers recognize
color: DarkGreen
specifies the hue, saturation, lightness, and alpha transparency
color: hsla(o, 100%, 100%, 0.5);
CSS treats each HTML element as if it were in a box, whether, it is an inline element or a block-level element