To get started using CSS to style HTML elements.
Web Programming book reading for THIS class
Web Programming book reading for NEXT class
span
and div
Elementsstyle
Attribute, style
ContainerAdditional References
Questions from our last class or the readings?
What are styles?
style
attribute
What is the purpose of styles?
<p style="color: red;">This is red text.</p>
This is red text.
element
┌────────────────────────┴────────────────────────────┐
attribute attibute element
name value content
┌─┴─┐ ┌────────────┴─────────────┐ ┌───┴───┐
<h2 style="text-decoration: underline;">Welcome!</h2>
└┬┘ └───────┬──────┘ └───┬───┘ └─┬─┘
opening CSS Property closing
tag Property Value tag
;
)
<p style="color: red ; font-style: italic ; text-decoration: underline">
This is red, italic, underlined text.</p>This is red, italic, underlined text.
<head>
section
Source: CSS: The Missing Manual by David Sawyer McFarland, Figure 2-2,
2nd edition: page 33, 3rd edition: p. 38
- each style sheet entry (as above) is called a rule
<head>
<style>
/* rules go here */
</style>
</head>
<head> <style> p { /* this rule applies to all p elements */ color: red ; font-style: italic ; text-decoration: underline ; } </style> </head> <body> <p>This is red, italic, underlined text.</p> <p>This text will also be red, italic, and underlined.</p> </body>This is red, italic, underlined text.
This text will also be red, italic, and underlined.
Syntax
tag { 1st-property: 1st-property’s-value; 2nd-property: 2nd-property’s-value; }➤ Notice the colon (
:
) between the property and its value and the semi-colon (;
) at the end of each rule.
Dean, Web Programming, p. 78
Dean, Web Programming, p. 78
Example
em { color : green ; /* we are adding properties to the em tag */ font-weight : bold ; /* the text will still render in italics because that property is built-in */ }
<p>This booklet was developed by residents, so it is <em>not</em> an official rule book.</p>
<p>You can have up to 20 people on your visitor list. If you remove someone from your list, he or she <em>cannot be added back on for one calendar year</em>.</p>
Result
This booklet was developed by residents, so it is not an official rule book.
You can have up to 20 people on your visitor list. If you remove someone from your list, he or she cannot be added back on for one calendar year.
➤ Remember that the text is italicized because italicization is a built-in property of the <em> tag. However, this can be changed by CSS, too.
/*
and */
symbolsGoal: To render the main part of PRO Manual page 15 in the browser so that it looks close to the way it looks in the manual, but with a few enhancements.
head
section. I have supplied a body
selector in
that sheet for which I added CSS rules to display the page text in a sans-serif font
(Verdana) and limit the page width to 600 pixels.color: blue ; color: green ; font-style: italic ; color: red ; font-weight: bold ; padding: 12px 24px ; border: 3px solid silver ; background-color: azure ; text-align: center ;
This is Class No. 3. It was last modified on
Saturday, October 21, 2023 at 4:38 PM. Copyright © 2010-2024 by Jesse M. Heines. All rights reserved, but may be freely copied or excerpted for
educational purposes with credit to the author.