Last updated 2017 January 15
When you are developing external style sheets your latest changes may not be loaded when you reload a page. To force a reload that reloads all linked files you press the CTRL or CLOVER key while clicking on the reload button. Keyboard shortcuts: CTRL-F5 works for Chrome and Internet Explorer; CTRL-SHIFT-R (CLOVER-SHIFT-R) for Firefox, and CTRL-R (CLOVER-R) works for both Safari and Chrome.
StyleSheet ::= +[ StyleElement ];
StyleElement ::= Selector Definition;
Selector ::= ( element
-- Selects all instances of the HTML/XML element
,
.identifier
-- selects all elements with the attribute class="identifier"
,
#identifier
-- selects the one element with the attribute id="identifier", avoid its use
);
Definition ::= '{' +[ PropertyValuePair ';' ] '}';
PropertyValuePair ::= PropertyName ':' PropertyValue;}
Items in blue are selectors.
Items in magenta are definitions.
body { background-color: #FFFF88; color: #000000; } li { margin-top: .5em; } .alignHorizontalCenter { width: 50%; margin-left: auto; margin-right: auto; } .academicHonesty { width: 50%; margin-left: auto; margin-right: auto; font-size: 1.5em; } .fixedFont { font-family: Georgia, "Times New Roman", serif; } /* Why can this be a list? Why is Times New Roman in quotes? */ #lastUpdated { font-style: italic; font-weight: bold; color: red; } #font13 { font-size: 1.3em; font-weight: bold; }
<p style="color: blue; font-size: 1.5em">Bigger font in blue</p>
Bigger font in blue
<head>
…
<style type="text/css">
.alignHorizontalCenter {
width: 50%;
margin-left: auto;
margin-right: auto; }
.academicHonesty {
width: 50%;
margin-left: auto;
margin-right: auto;
font-size: 1.5em; }
body {
background-color: #FFFF88;
color: #000000; }
</style>
</head>
<head>
…
<link rel="stylesheet" type="text/css" href="../styleBase.css">
</head>
… style text /* comment text
can span lines
*/
more style text …
The rules of precedence mean that the definition most local or closest to the displayed data take precedence over definitions further from the displayed data.
Cascade example — Remove style definitions in the HTML file and see the background change color from yellow to blue, and the first paragraph change color from blue to yellow.
Some styles are inherited from the parent element. For example, fonts, font size.
Some are not inherited. For example, margins and padding.
Inheritance is indicated by using the keyword inherit as a property value.
color: inherit
h1 {color: black !important; }
WARNING:
Try to avoid using important
The source of this idea is here.