Page Sections

CSE 190 M (Web Programming), Spring 2008

University of Washington

Reading: Chapter 1, section 1.4;
Chapter 2, sections 2.1 - 2.2

Except where otherwise noted, the contents of this presentation are © Copyright 2008 Marty Stepp and Jessica Miller and are licensed under the Creative Commons Attribution 2.5 License.

Valid XHTML 1.1 Valid CSS!

Motivation for Page Sections

flow

The HTML id attribute

<p>Spatula City!  Spatula City!</p>
<p id="missionstatement">Our mission is to provide the most
spectacular spatulas and splurge on our specials until our
customers <q>esplode</q> with splendor!</p>

Spatula City! Spatula City!

Our mission is to provide the most spectacular spatulas and splurge on our specials until our customers esplode with splendor!

CSS ID selectors

#missionstatement {
	font-style: italic;
	font-family: "Garamond", "Century Gothic", serif;
}

Linking to sections of a web page

<p>Visit <a href=
"http://www.textpad.com/download/index.html#downloads">
textpad.com</a> to get the TextPad editor.</p>
<p><a href="#mac">Directions for Mac OS X</a></p>

Visit textpad.com to get the TextPad editor.

Directions for Mac OS X


The HTML class attribute

<p>Spatula City!  Spatula City!</p>
<p class="special">See our spectacular spatula specials!</p>
<p class="special">Today only: satisfaction guaranteed.</p>

Spatula City! Spatula City!

See our spectacular spatula specials!

Today only: satisfaction guaranteed.


CSS class selectors

.special {
	background-color: yellow;
	font-weight: bold;
}
p.standout {
	color: red;
	font-family: cursive;
}

Multiple classes

<h2 class="standout">Spatula City!  Spatula City!</h2>
<p class="special">See our spectacular spatula specials!</p>
<p class="special standout">Satisfaction guaranteed.</p>
<p class="standout">We'll beat any advertised price!</p>

Spatula City! Spatula City!

See our spectacular spatula specials!

Satisfaction guaranteed.

We'll beat any advertised price!


Sections of a page: <div>

a section or division of your HTML page (block)

<div class="standout">
	<h2>Spatula City!  Spatula City!</h2>
	<p class="special">See our spectacular spatula specials!</p>
	<p>We'll beat any advertised price!</p>
</div>

Spatula City! Spatula City!

See our spectacular spatula specials!

We'll beat any advertised price!


Inline sections: <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="standout">any advertised
price</span>!</p>

Spatula City! Spatula City!

See our spectacular spatula specials!

We'll beat any advertised price!


CSS context selectors

selector1 selector2 {
	properties
}
selector1 > selector2 {
	properties
}

Context selector example

li strong { text-decoration: underline; }
<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>

Shop at Hardwick's Hardware...

More complex example

#ad li.important 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 in town!</li>
		<li>Act <strong>while supplies last!</strong></li>
	</ul>
</div>

Shop at Hardwick's Hardware...

CSS properties for backgrounds

background-image

body {
	background-image: url("draft.jpg");
}

This is the first paragraph

This is the second paragraph...
It occupies 2 lines


background-repeat

body {
	background-image: url("draft.jpg");
	background-repeat: repeat-x;
}

This is the first paragraph

This is the second paragraph...
It occupies 2 lines


background-position

body {
	background-image: url("draft.jpg");
	background-repeat: no-repeat;
	background-position: 370px 20px;
}

This is the first paragraph

This is the second paragraph...
It occupies 2 lines


Showing a partial image

.partialimage1, .partialimage2 {
	background-image: url("sex_and_the_city.jpg");
	background-repeat: no-repeat;
	width: 70px;   height: 200px;
}
.partialimage1 { background-position: 0px 0px; }
.partialimage2 { background-position: -115px 0px; }
sex and the city