HTML5 Authoring 4
HTML5 Authoring 4
CSS (Cascading Style Sheet language) provides the design layer to web based, and much
mobile content. It is a mark up language that allows you, as the developer, to set rules
governing how content should appear on the users’ screens.
This has become more challenging of late because we no longer live in a world where
screen size, resolution, bandwidth and other factors are predictable. People viewing your
content may range from someone in an office with a fiber internet connection and a giant
screen, to someone in subsaharan Africa with a cell phone, slow connection and tiny screen.
Fortunately CSS has both the power and the flexibility to produce styles that look great
across the range of devices in use on today’s internet.
Understanding the “mechanicals” of CSS are just one aspect of producing digital content. You also have to
understand the rules of digital design and usability. Designing interfaces that are usable and look good is a
separate, related field to web development known as UX (User eXperience). You my find UX is a good direction to
move in if you want to spend more time creating designs than writing code.
You won’t escape the coding entirely, however, as today, almost all UX designers have a firm grip of HTML5 and
CSS.
The selector in this case is p. This means that any <p> tags would be selected and styled.
(There are numerous other types of selectors that we’ll get in to later in the course).
The style rules should be somewhat understandable just from reading them. In the case
above, we’re applying two style rules to the <p> tags. The first rule applies a deep gray color
to the text. The second sets the size of the text to 14 points. Note that each CSS style rule is
terminated by a semicolon.
Let’s take a look at a second example:
h3 {
text-decoration: underline;
}
This rule would apply an underline to any h3 tags appearing in the document.
As is true with many aspects of digital development, there are several methods you can use
to apply CSS code. Let’s look at the three primary methods individually:
Inline CSS
Inline CSS is applied via the HTML <style> tag. This method is commonly used with HTML
emails because an external style sheet is not possible.
Internal CSS looks like this:
<h1 style="color: red; font-size: 24pt;">I'm Stylin'</h1>
The <h1> element here would appear red in a 24 pt size. The result would look like this:
Outside of use with HTML emails, the use of inline styles is not considered a best practice.
Well formed CSS should be able to be easily:
• Edited within a document. With inline CSS each individual instance of CSS must be
located and edited.
• Applied to multiple elements on multiple pages lending to style consistency across a
site.
In this brief style sheet we’ve created style rules that apply to <h1> and <h2> tags within
our document.
strong {
color: red;
}
em {
color: blue;
}
You should be able to tell from context what the style rules do in this case. To attach the
myStyles.css file to the HTML document the following line should appear in the <head>
section of the HTML document:
<link href="myStyles.css" rel="stylesheet" type="text/css"/>
There are a couple of things to note here about the <link> tag. First the href attribute
should point to the path and filename for your CSS. In the case above the CSS appears in the
same folder as the HTML. The rel attribute and the type attribute always appear as shown
here and are required.
Like the <br/> tag, the <link /> tag is an empty tag and uses the / character at the end of
the tag to self-close.
Rule
color Sets the color of text in rgb, hex or color-name format
letter-spacing Sets space between characters in text
line-height Sets the height of an individual line.
text-align Right, Center, Left Align or Justify your text
text- Sets underline, or overline on text
decoration
text-indent Specifies indent on first line of text
text-shadow Specifies a drop shadow on text
text- Controls the Capitalization of text
transform
vertical-align Set the vertical alignment of your text
font-family Set the typeface for text
font-size Sets the font-size of text
font-style Sets the style in which font is presented. “Normal”, “Italic” and “Oblique”
are the options.
font-variant Allows use of small caps (Where lower case letters are represented by
smaller upper-case letters)
font-weight Sets the boldness of text.
Some of these rules, like font-size require a measurement. CSS is very flexible when it
comes to measuring type. Below is a chart of the most common types measurements that
are available.
Despite the flexibility afforded by CSS, most developers stick to px, pt, and em. Because it’s a
relative measurement that respects the users preferences em is becoming the most
accepted type measurement unit.
westportcss.css
hl
{
font-family: Verdana
font-size: 1.75mem
font-weight: bold
text-decoration: none
font-variant: mall-caps
color: rgb(75,0,100)
}
p
{
line-height: 2em
text-align: left
}
With errors corrected your file should appear like this:
Code Exercise:
Find or write a paragraph or two about your hometown or about a location that you like.
(Wikipedia is a good source for this-- Make sure you give appropriate credit in your
document!) Create correctly styled HTML5 and use appropriate markup
Using some of the CSS properties we’ve discussed in this section, create a pleasing and
readable design for your document. Use an external CSS file to create your typography.
(There is no correct or incorrect for this lab as long as your CSS correctly styles your HTML
document!)
Have some fun with this!