CSS For Beginners
CSS For Beginners
CSS For Beginners
What?
CSS, or Cascading Styles Sheets, is a way to style and
present HTML. Whereas the HTML structure is the
semantic meaning or content, the style sheet is the
presentation of that content.
CSS styles consist of property: value They can be
applied to most HTML tags. This is done in one of
three ways: inline, internally, and externally, via a
style sheet.
Application
The most basic application of CSS is to apply it inline
directly to an HTML tag via an attribute:
<p style="color: blue">Some text here.</p>
Applying this attribute would render this specific
paragraph in blue.
However, the best-practice approach is to separate
the HTML from the presentation. Imagine if you had
100 <p> tags where you wanted to change the color
from blue to a dark gray. Internally inserted styles are
used inside the head element of that page, and apply
directly to that page only. This is a way of separating
content (HTML) from presentation (CSS).
<!DOCTYPE html>
<html>
<head>
<title>CSS Test</title>
<style>
p{
color: #333;
}
a{
color: #999;
}
</style>
</head>
Selector
body {
font-size: 12px;
color: #333;
}
properties, each
line separated with
semi-colon.
Closing curly bracket
* { font-size: 12pt; }
Color
text-decoration
This specifies text related to underlines and strikethroughs (used mainly for links).
text-decoration: underline;
places a line under the text (default for links).
text-decoration: overline
text-transform
p{
font-family: "Times New Roman", Georgia, Serif;
}
There are two types of font family names:
family-name - The name of a font-family, like "times",
"courier", "arial", etc.
generic-family - The name of a generic-family, like
"serif", "sans-serif", "cursive", "fantasy", "monospace".
Start with the font you want, and always end with a
generic family, to let the browser pick a similar font in
the generic family, if no other fonts are available.
Important: If a font name contains white-space, it
must be quoted.
font-size
This relates to the size of the font. Examples:
font-size: 16px;
font-size: 1.5em;
font-size: 80%;
font-style
This property states italic text: font-style: italic;
text-decoration: none;
Eliminates the default underline on links.
Text spacing
The letter-spacing and word-spacing properties are
for spacing between letters or words. The value can
be a specific length or "normal."
text-align: center;
}
Borders
To create a border around an element, use the
border-style property. The values can be selected
from: solid, dotted, dashed, double, groove, ridge,
inset and outset.
The border-width property sets the width of the
border, most commonly using pixels as a value. There
are also properties for border-top-width, borderright-width, border-bottom-width and border-leftwidth.
Finally, the border-color property sets the color.
h1 {
border-style: dashed;
border-width: 2px;
border-left-width: 5px;
border-right-width: 5px;
border-color: #333;
}
This will render a gray dashed border around all
HTML headers (the h1 element), 2pixels wide on the
top and bottom and 5 pixels wide on the left and
right (overriding the 2 pixel width of the entire border
since they are specified after).
So What Now?
The code below covers all of the CSS methods
discussed this week. If you save your CSS file and test
& preview the HTML file, you should now begin to
understand what each CSS property does and how
to apply them.
h3 {
color: #999;
font-size: 1.25em;
}
img {
body {
font-family: "Times New Roman" ,Georgia, Serif;
font-size: 16px;
color: #333;
background-color: #f1f1f1;
margin: 15px;
padding: 0;
}
border-style: solid;
border-width: 1px;
border-color: #ccc;
}
a{
text-decoration: none;
}
p{
line-height: 2;
strong {
font-style: italic;
text-transform: uppercase;
h1 {
color: #122b64;
font-size: 2.5em;
margin: 0;
margin-bottom: 7px;
padding: 5px;
text-align: center;
letter-spacing: 0.5em;
border-bottom-style: solid;
border-bottom-width: 2px;
border-bottom-color: #c00;
}
li {
color: #1b2e1e;
font-style: italic;
}
table {
background-color: #fff3bc;
}
h2 {
color: # 330000;
font-size: 1.5em;
margin: 0;
padding: 2px;
padding-left: 10px;
}