
Style Sheets
- Style sheets control the appearance of an HTML page.
- Control colors, fonts, position, spacing, rules, outlines.
- Alternative to some of the attributes we've already learned.
- Style sheets are considered the preferable way to do this.
- They form a kind of language embedded within HTML.
- Set style parameters with a keyword: value format.
color: red
- Set several by separating with a semicolon.
color: red; font-size: 120%
- There are many variables to set.
Here
is the list from W3Schools.
- Three places to specify.
- In-line styles are given by a style attribute.
[ Inline Styles ]
- Most tags take a style.
- The <span>...</span> tag can be used for applying style to
arbitrary text.
- The <div>...</div> tag can be used for applying style to
larger sections involving multiple paragraphs or other block
items.
- Embedded style sheets. [ Embedded Styles ]
- Given in a <style>...</style>
section in the header.
- Often enclosed in comments to prevent cows by old browsers.
- Uses the name of a tag to tell what the styles
that tag should use: h1 { color: red }
- Advantages.
- Assign consistent styles for the whole page.
- Specify everything once in one place; One place to change.
- Can reduce page size.
- External style sheets are linked.
[ External Styles ]
[ Style Sheet ]
- In the header, say
<link rel="stylesheet" href="url" type="text/css" />
instead of a <style>...</style> section.
- The type is probably not needed, but safe.
- Advantages:
- Allows the styles for a site to specified in one place.
- Gives site a consistent look.
- Allows whole site's look to be changed by changing one document.
- Browser will cache the sheet, so download may be reduced
across the site.
- The controlling style is the one closest to the text. In-line beats
embedded, embedded beats external.
- Inheritance: Attributes are inherited from the enclosing tag.
For instance, the <body> styles are generally inherited
by everything in the body.
- Style classes. [ Style Classes ]
- You don't always want to apply the same style to every <p> or
<h2>.
- You can create different style classes like this:
p.fred { font-size: 16pt }
- You can refer to the class with the class attribute:
<p class="fred">...</p>
- You can create general classes without just a dot:
.barney { color: #00AA00 }
These can be used with class on any sort of item.
- When the class attribute is not given, the base style is
used.
- Colors and Fonts. [ Fonts And Colors ]
- Colors: color, bgcolor
- Font: font-family: , font-size: , font-style: , font-weight:
- font-family: : Specific:
times, courier, ariel, or general:
serif, sans-serif, cursive, fantasy, monospace.
- line-height: Set a percentage or multiplier to adjust.
- Box model
- From inside out: content, padding, border, margin.
- Several bazillion ways to control all of these. margin-top,
margin-right, etc. padding-top, padding-right, etc.
text-align, text-indent, text-transform.
- [ Common Style Sheet ]
- [ Margins ]
- Box Position [ Boxes ]
- The position attribute.
- Absolute: Position is from the edges of the screen.
- Relative: Position is from the location where the box would
be without the attribute.
- Where: left, right, bottom, top: The location of
the indicated edge of the box. Back from the outside box.
- List properties. [ Lists ]
- list-style-type: Choose a bullet, much like the type
attribute, but more flexible.
- list-style-image: Use an image bullet.
- list-style-position: How the bullet or number is located.
- Inverted L with style sheets. [ Inverted L ]
[ Joe Style ]
- Background image. background-image,
background-position, background-repeat,
background-attachment
- Size is important, since the image covers the size of the
area.
- Example: [ Joe's With Handles ]
- Example: [ One centered handle ] Note that it
is centered on the page, not in the region it is specified for.
- Example: [ Vertical repeat ].
- Example: [ Fixed ].
- Link colors: a:link, a:visited, a:hover, a:active.
[ Links ].
- More Examples.
- Tab links: [ Smigglish ] [ Style Sheet ]
- [ Drop Down ]
- Tab
example (offsite).
- [ z-index ]
- [ Fixed Menu ]
- [ Using + in selectors ]
- Server-Side Includes.
- The [ Zebras ].
- What it contains
- Zebra Header