Attribution:Except where otherwise noted, the contents of this document are Copyright 2012 Marty Stepp, Jessica Miller, and Victoria Kirst. All rights reserved. Any redistribution, reproduction, transmission, or storage of part or all of the contents in any form is prohibited without the author's expressed written permission.
Otherwise noted: Claude Anderson was given permission to modify the slides for CSSE 290 at Rose-Hulman by author Jessica Miller.
The authors' original slides, based on Web Programming Step by Step, can be seen at http://webstepbook.com.
Some of the examples in some days' slides are from David Fisher at Rose-Hulman, who was kind enough to allow me to use them.
My intention is to mark these examples with [DSF].
property | description |
---|---|
text-align
|
Alignment of text within its element (left , right , center , justify )
|
text-decoration
|
Decorations such as underline, overline, strikethrough |
text-indent
|
Indents the first letter of each paragraph |
text-shadow
|
A colored shadow near an existing piece of text |
line-height , word-spacing , letter-spacing
|
Gaps between the various portions of the text |
text-transform
|
Change text case to lowercase , uppercase , or capitalize
|
Complete list of text properties |
Details of some of these on the next few slides
text-align
blockquote { text-align: justify; } h2 { text-align: center; }
[TO LUKE SKYWALKER] The alliance... will die. As will your friends. Good, I can feel your anger. I am unarmed. Take your weapon. Strike me down with all of your hatred and your journey towards the dark side will be complete.
Follow the yellow link and look through the kinds of information there. Focus on "inherited:yes."
left
, right
, center
, or justify
(which widens all full lines of the element so that they occupy its entire width) text-transform
h2 { text-transform: uppercase; } h3 { text-transform: lowercase; }
lowercase
uppercase
capitalize
none
inherit
text-decoration
p { text-decoration: underline; }
This paragraph uses the style above.
overline
underline
line-through
none
text-decoration: overline underline;
Follow the yellow link and notice that this property is not inherited, but that it can be, using the inherit value.
text-shadow
p { font-weight: bold; text-shadow: -2px 5px gray; }
This paragraph uses the style above.
list-style-type
Property
ol { list-style-type: lower-roman; }
none
: No markerdisc
(default), circle
, square
decimal
: 1, 2, 3, etc.decimal-leading-zero
: 01, 02, 03, etc.lower-roman
: i, ii, iii, iv, v, etc.upper-roman
: I, II, III, IV, V, etc.lower-alpha
: a, b, c, d, e, etc.upper-alpha
: A, B, C, D, E, etc.lower-greek
: alpha, beta, gamma, etc.hebrew
, armenian
, georgian
, cjk-ideographic
, hiragana
, katakana
, hiragana-iroha
, katakana-iroha
list-style-image
,
list-style-position
, and
list-style
property | description |
---|---|
background-color
|
Color to fill background |
background-image
|
image to place in background |
background-position
|
Placement of bg image within element |
background-repeat
|
Whether/how bg image should be repeated |
background-attachment
|
Whether bg image scrolls with page |
background
|
Shorthand to set all background properties |
background-image
body { background-image: url("images/draft.jpg"); }
This is the first paragraph
This is the second paragraph...
It occupies 2 lines
background-repeat
body { background-image: url("images/draft.jpg"); background-repeat: repeat-x; }
This is the first paragraph
This is the second paragraph...
It occupies 2 lines
repeat
(default), repeat-x
, repeat-y
, or no-repeat
background-position
body { background-image: url("images/draft.jpg"); background-repeat: no-repeat; background-position: 370px 20px; }
This is the first paragraph
This is the second paragraph...
It occupies 2 lines
top
, left
, right
, bottom
, center
, a percentage, or a length value in px
, pt
, etc.table { border: 2px solid black; caption-side: bottom; } tr { font-style: italic; } td { background-color: yellow; text-align: center; width: 30%; }
Column 1 | Column 2 |
---|---|
1,1 | 1,2 okay |
2,1 real wide | 2,2 |
border-collapse
Propertytable, td, th { border: 2px solid black; } table { border-collapse: collapse; }
Column 1 | Column 2 |
---|---|
1,1 | 1,2 |
2,1 | 2,2 |
Column 1 | Column 2 |
---|---|
1,1 | 1,2 |
2,1 | 2,2 |
border-collapse
property merges these borders into onerowspan
and
colspan
Attributes<table> <tr><th>Column 1</th><th>Column 2</th><th>Column 3</th></tr> <tr><td colspan="2">1,1-1,2</td> <td rowspan="3">1,3-3,3</td></tr> <tr><td>2,1</td><td>2,2</td></tr> <tr><td>3,1</td><td>3,2</td></tr> </table>
colspan
tag makes a cell occupy multiple columns; rowspan
multiple rowstext-align
and
vertical-align
CSS properties control where the text appears within a cell<col>
,
<colgroup>
<table> <col class="urgent" /> <colgroup class="highlight" span="2"></colgroup> <tr><th>Column 1</th><th>Column 2</th><th>Column 3</th></tr> <tr><td>1,1</td><td>1,2</td><td>1,3</td></tr> <tr><td>2,1</td><td>2,2</td><td>2,3</td></tr> </table>
col
tag can be used to define styles that apply to an entire column (self-closing)colgroup
tag applies a style to a group of columns (NOT self-closing).urgent { background-color: pink; } .highlight { background-color: yellow; }
table
has semantics; it should be used only to represent an actual table of datadiv
s, widths/margins, floats, etc. to perform layouth2 { border: 5px solid red; }
property | description |
---|---|
border
|
thickness/style/color of border on all 4 sides |
px
, pt
, em
, or thin
, medium
, thick
)none
,
hidden
,
dotted
,
dashed
,
double
,
groove
,
inset
,
outset
,
ridge
,
solid
,
hidden
)
property | description |
---|---|
border-color ,
border-width , border-style
|
specific properties of border on all 4 sides |
border-bottom ,
border-left , border-right ,
border-top
|
all properties of border on a particular side |
border-bottom-color ,
border-bottom-style , border-bottom-width ,
border-left-color , border-left-style ,
border-left-width , border-right-color ,
border-right-style , border-right-width ,
border-top-color , border-top-style ,
border-top-width
|
properties of border on a particular side |
h2 { border-left: thick dotted #CC0088; border-bottom-color: rgb(0, 128, 128); border-bottom-style: double; }
border-bottom-width
above)nth-child
, inline-block
, :not
, +
body { font-size: 16px; }
body
elementbody { color: green; } p, h1, h2 { color: blue; font-style: italic; } h2 { color: red; background-color: yellow; }
This paragraph uses the first style above.
.css
files<link>
tag in the page header)<style>
tag in the page header)style
attribute of an HTML element)body { font-family: sans-serif; background-color: yellow; } p { color: red; background-color: aqua; } a { text-decoration: overline underline; } h2 { font-weight: bold; text-align: center; }
A styled paragraph. Previous slides are available on the web site.
a:link { color: #FF0000; } /* unvisited link */ a:visited { color: #00FF00; } /* visited link */ a:hover { color: #FF00FF; } /* mouse over link */
class | description |
---|---|
:active
|
an activated or selected element |
:focus
|
an element that has the keyboard focus |
:hover
|
an element that has the mouse over it |
:link
|
a link that has not been visited |
:visited
|
a link that has already been visited |
:first-letter
|
the first letter of text inside an element |
:first-line
|
the first line of text inside an element |
:first-child
|
an element that is the first one to appear inside another |
:nth-child(N)
|
applies to every Nth child of a given parent |
id
Attribute
<p>Spatula City! Spatula City!</p> <p id="mission">Our mission is to provide the most spectacular spatulas and splurge on our specials until our customers <q>esplode</q> with splendor!</p>
<p>Visit <a href= "http://www.textpad.com/download/index.html#downloads"> textpad.com</a> to get the TextPad editor.</p> <p><a href="#mission">View our Mission Statement</a></p>
#
#mission { font-style: italic; font-family: "Garamond", "Century Gothic", serif; }
Spatula City! Spatula City!
Our mission is to provide the most
spectacular spatulas and splurge on our specials until our
customers esplode
with splendor!
mission
p#mission {
class
Attribute
<p class="shout">Spatula City! Spatula City!</p> <p class="special">See our spectacular spatula specials!</p> <p class="special">Today only: satisfaction guaranteed.</p>
I don't want ALL paragraphs to be yellow, just these three...)
id
, a class
can be reused as many times as you wish on a pageclass
attribute to a tag does nothing until we use that class in CSS or in JavaScript code..special { /* any element with class="special" */ background-color: yellow; font-weight: bold; } p.shout { /* only p elements with class="shout" */ color: red; font-family: cursive; }
Spatula City! Spatula City!
See our spectacular spatula specials!
Today only: satisfaction guaranteed.
special
, and to any p
element with class shout
<h2 class="shout">Spatula City! Spatula City!</h2> <p class="special">See our spectacular spatula specials!</p> <p class="special shout">Satisfaction guaranteed.</p> <p class="shout">We'll beat any advertised price!</p>
See our spectacular spatula specials!
Satisfaction guaranteed.
We'll beat any advertised price!
.special { background-color: yellow; font-weight: bold; } .shout { color: red; font-family: cursive; }
<div>
A section or division of your HTML page (block)
<div class="shout"> <h2>Spatula City! Spatula City!</h2> <p class="special">See our spectacular spatula specials!</p> <p>We'll beat any advertised price!</p> </div>
See our spectacular spatula specials!
We'll beat any advertised price!
div
tag is used to indicate a logical section or area of a page.special { background-color: yellow; font-weight: bold; } .shout { color: red; font-family: cursive; }
<span>
an inline element used purely as a range for applying styles
<h2>Spatula City! Spatula City!</h2> <p>See our <span class="special">spectacular</span> spatula specials!</p> <p>We'll beat <span class="shout">any advertised price</span>!</p>
See our spectacular spatula specials!
We'll beat any advertised price!
span
.special { background-color: yellow; font-weight: bold; } .shout { color: red; font-family: cursive; }
selector1 selector2 { properties }
selector1 > selector2 { properties }
<p>Shop at <strong>Hardwick's Hardware</strong>...</p> <ul> <li>The <strong>best</strong> prices in town!</li> <li>Act while supplies last!</li> </ul>
li strong { text-decoration: underline; }
<div id="ad"> <p>Shop at <strong>Hardwick's Hardware</strong>...</p> <ul> <li class="important">The <strong>best</strong> prices!</li> <li>Act <strong>while supplies last!</strong></li> </ul> </div>
#ad li.important strong { text-decoration: underline; }
* Slides and exercises from Dave's GoogleApps course used with permission.
In the future, this course will be a prerequisite for that one, so these slides will probably no longer be used there.