Stylesheets
Stylesheets
Books use the term "stylesheets" to include:
- external css files
- styles inserted between the head tags
- styles inserted within tags inside the body.
This muddling of terms I find confusing. It is natural to define them in this way:
- stylesheet: external css files
- head styles: styles inserted between the head tags
- body tag styles: styles inserted within the body tag
- tag styles: styles inserted within any tags inside the body.
Overwriting styles
External stylesheets are usually the most efficient way to write styles because the one css file can be linked into 6000 files.
Where the external stylesheet needs to be overwritten, then include styles within the head tags, as in:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>index</title>
<style type="text/css">
a:link, a:visited, a:active, a:focus {color:#ffaa33; text-decoration:none}
a:hover{color:#ffffaa; text-decoration:none}
body{
background-color:#8b0000;color:#ffaa33;
font: bold 12pt Arial;text-align:left;
padding-left: 5px;
}
hr{size:2px;color:#ffaa33;}
hr.40{width:40%;align:left}
.f18{font-size:18pt}
.g(color:green}
</style>
</head>
Where the style in the head needs to be overwritten, then insert the changed style into tags within the body, as in:
<div style="color:blue"> Hi ! My color is blue.</div>
If you have defined a style in an external stylesheet or in the head of the file, as in hr.40 or .f18 or .g above, then you can use classes as in:
<div class="f18 g"> My font is 18pt and green.</div>
Styles
Within a set of styles:
- body{} sets the body style for all files linking to this stylesheet or head style.
- table{} sets the table style for all files linking to this stylesheet or head style. Just script <table> and the style will automatically be used.
- .b3{} sets the style for any tag which calls upon it, such as <table style="b3"> or <table class="b3">. This replaces the style called by <table>.
- table.b3{} enables us to override the styles set by table{}. This overriding is done by calling b3 from within the table tag, as in <table style="b3"> or <table class="b3">. However the style set by table.b3{} is limited to the table tag, whereas the style set by .b3{} can be called by <table>, <div>, <box>, and many more.
- We can use .b3{} but not .3b{} because some browsers do not allow classes to begin with a digit (example Mozilla Firefox).
- If you do not define a style, the browser will use its own default style, which might wreck the format of your carefully scripted page.
- .h2{font:bold 18pt/36pt Times;text-align:center} Headings h1, h2, ..., h6 have enormous line-heights (gross). Heading h4 has line-height about 54pt compared to the desired the 36pt chosen for all my heading classes. Setting line-height of headings to 8pt (as in 18pt/8pt) counter-acts this but might fail with some browsers, besides appearing ridiculous.
Notes on my styles
When learning scripting in HTML, my stylesheets grew and grew till several pages long. Now they have been reduced to a skeleton of 18 items. If any more styles are needed, they are scripted into the relevant tag on the spot or, if required frequently in the document then they go into the <head>.
After 4 years of scripting and re-scripting, designing and re-designing, with about 12 months or more wasted just re-doing in the hope of doing it better (more user-friendly, faster downloading), my guiding principle is a vehement KISS - keep it simple, stupid !
The simpler the better – the faster to download, the faster to write, check and maintain, the more user-friendly.
No pop-ups, no advertizing, no bells-n-whistles, just plain straight information.
No javascript, no applets, minimum styles, minimum frames, minimum formating, minimum indexing:
- 1st click to enter the Main Index: Core, School, Teaching, etc.
- 2nd click to grab the subject index: Chemistry, Crafts, etc.
- 3rd click to grab the topic and its sub-topic: eg ketones in Organic Chemistry.
- Main index is always in view on the left.
- To return from the document to the subject index, close the window.
- Possible to have the Main Index, Subject Index and Document open at the same time.
- No cross-linking to fail when files are moved or renamed.
- No PHP, no Javascript, no Applets, to slow downloading or confuse those without such facilities.
- Scripting is minimized. This minimizes file-size and documentation. Minimum use of tables; minimum use of rows within tables.
- Minimum file sizes. For downloading, about 20KB file-size is preferred because of poor Internet connections. For using on a HDD or CD, 31KB is preferred because hard-disk space is allotted to files in multiples of 16KB. Which means there is no advantage in using PHP to compile files on the server.
- Directory hierarchy is minimized (from index.htm inside f2, there are 2 directories at most, such as K/SB_biology/A1_INTRO.htm) to reduce processing. Directories are files containing the addresses of the files it contains - one more file to open and search.
- By addressing files with the first character used less than 10 times and the 2nd character used once, search times are minimized.
- The name of the first file in each batch, names the batch and uses uppercase to catch the webmaster's eye.
- Changing a file-name necessitates only one other change, namely, in the subject index.
- Changing an id inside a file necessitates only one other change, namely, in the subject index.
Very user-friendly. KISS.
The symbols /* ... */ indicate comments made to help future webmasters, but, since they are ignored by the browser, these comments are not printed to the user's screen.
@charset "utf-8";
/* Placed on the first line of the css file and written within meta tags within head tags on all content files. Tells the browser that the script is in utf-8 coding, not ANSCII or some other. */
body {
/* margin = distance between outer element (frame) and this inner element (body).
padding = distance between this element and its content;
not inherited, being reset to zero; cannot be negative.
Frames have 5px margins, so body does not need margins. */
background-color:#fff8d6;color:#400000;
font-family: "Times New Roman";font-size: 12pt;
border: solid 2px #400000;padding:em;
/* Puts a border around the whole document, inside the frame's margin of 5px.
The padding of 1em is the width of the letter 'M' in the current font-size.
Subtract the size of the border to give the distance between the border and the text. */
scrollbar-face-color: #8b0000 <!-- not valid but IE recognizes it; Firefox does not. -->
} closing parenthesis for body{}.
table{border:0px none;background-color:transparent;font:normal 12pt/14pt "Times New Roman"}
th{background-color:} gives color to headings of table
td{padding:left:0.5em;padding:right:0.5em} ensures cell data looks neat.
.b3{border:3px double #8b0000;background-color:#ffe4b5}
ul{padding-let:0em} removes the indentation of text after the list and avoids the need to use <br />
.b2{border:solid 2px #400000;padding:1em} /* padding-left:1em is the distance from the border to the text;
margin-left is the distance from the edge of the body, to this border, that is, it moves the object (surrounded by this border) to the right. */
.b3{border:3px double #8b0000;background-color:#ffe4b5}
.b4{border:double 10px #400000;background-color:#ffe4b5;color:#400000;padding:2em}
| Heading1 | Heading2 |
| Heading1 | Heading2 |
|---|
| Data11 | Data12 | | Data21 | Data22 |
| Heading1 | Heading2 |
|---|
| Data11 | Data12 | | Data21 | Data22 |
| Heading1 | Heading2 |
|---|
| Data11 | Data12 | | Data21 | Data22 |
| Heading1 | Heading2 |
|---|
| Data11 | Data12 | | Data21 | Data22 |
|
| Heading1 | Heading2 |
|---|
| Data11 | Data12 | | Data21 | Data22 |
| Heading1 | Heading2 |
|---|
| Data11 | Data12 | | Data21 | Data22 |
| Heading1 | Heading2 |
|---|
| Data11 | Data12 | | Data21 | Data22 |
| Heading1 | Heading2 |
|---|
| Data11 | Data12 | | Data21 | Data22 |
|
The scripting for the above tables is here:
Here is the table which encloses all the other tables.
It has a border and rules, which are internal borders. I called up the internal borders with border="3px". Later I use border="1px"/"2px"/"3px" but the width remains fixed at what seems to be 4px. Even the larger "10px" has no effect.
<table class="b3" border=".">
<thead><tr><th>Heading1</th><th>Heading2</th></tr></thead>
thead = "table head". tr = "table row". th = "table header".
<tbody> tbody = "table body".
<tr> tr = "table row".
<td> td = "table data".
Here is the first table in the left column.
It is borderless because in my stylesheet, K2.css, I defined it without borders.
<table>
<thead><tr><th>Heading1</th><th>Heading2</th></tr></thead>
<tbody>
<tr><td>Data11</th><td>Data12</th></tr>
<tr><td>Data21</th><td>Data22</td></tr>
</tbody>
</table>
Here is the 2nd table in the left column, with a solid brown border.
<table class="b2">
<thead><tr><th>Heading1</th><th>Heading2</th></tr></thead>
<tbody>
<tr>
<td>Data11</td><td>Data12</td>
</tr>
<tr>
<td>Data21</td><td>Data22</td>
</tr>
</tbody>
</table>
Here is the 3rd table in the left column, with a red double border.
<table class="b3">
<thead><tr><th>Heading1</th><th>Heading2</h></tr></thead>
<tbody>
<tr><td>Data11</td><td>Data12</td></tr>
<tr><td>Data21</td><td>Data22</td></tr>
</tbody>
</table>
Here is the 4th table in the left column, with a brown double border.
<table class="b4">
<thead><tr><th>Heading1</th><th>Heading2</th></tr></thead>
<tbody>
<tr><td>Data11</td><td>Data12</td></tr>
<tr><td>Data21</td><td>Data22</td></tr>
</tbody>
</table>
</td> This ends the first cell (left column) in the big table.
<td> This begins the next cell (right column) in the big table. The only difference is the addition of border="", inside the table tags of the 2nd, 3rd and 4th tables.
<table>
<thead><tr><th>Heading1</th><th>Heading2</th></tr></thead>
<tbody>
<tr><td>Data11</td><td>Data12</td></tr>
<tr><td>Data21</td><td>Data22</td></tr>
</tbody>
</table>
<table class="b2" border="1px">
<thead><tr><th>Heading1</th><th>Heading2</th></tr></thead>
<tbody><tr><td>Data11</td><td>Data12</td></tr>
<tr><td>Data21</td><td>Data22</td></tr>
</tbody>
</table>
<table class="b3" border="2px">
<thead><tr><th>Heading1</th><th>Heading2</th></tr></thead>
<tbody>
<tr><td>Data11</td><td>Data12</td></tr>
<tr><td>Data21</td><td>Data22</td></tr>
</tbody>
</table>
<table class="b4" border="3px">
<thead><tr><th>Heading1</th><th>Heading2</th></tr></thead>
<tbody><tr><td>Data11</td><td>Data12</td></tr>
<tr><td>Data21</td><td>Data22</td></tr>
</tbody>
</table>
</td> This ends the 2nd cell of data in the big table.
</tr> This ends the first (and only) row of the big table.
</tbody> This ends the table body.
</table> This ends the big table with its 2 columns.
.chemeq{font:normal 12pt/20pt Arial}
/* for tables containing chemistry equations. 12pt/20pt = font-size/line-height. This extra line-height is needed for the subscripts of chemical formulas.*/
.matheq{font:normal 12pt/40pt Arial}
/* for tables containing math equations. 12pt/20pt = font-size/line-height. This extra line-height is needed for the numerator/denominator of math equations. */
.u{text-decoration:underline}
/* class="b u" works only if b precedes u. */
h5{font:bold italic 12pt Arial;}
/* h tags are always bold in IE, but normal in Firefox unless font-weight:bold is inserted here. */
.p1{padding-left:1em}
/* In CSS, 1em = font-size.
class="p5" works with <div>, <ltd>, but not with <tr>, <tbody>, or <table>
Style="padding:0.5em" is valid.*/
.m1010{margin-left:10%;margin-right:10%;text-align:justify;font-style:italic;}
/* use div class="m1010", instead of blockquote. */
.m10{margin-left:10%;}
/* also works in tables with class="m10" */
ul{display:inline;list-style-type:square;list-style-position:outside;}
/* display:inline removes line break.
outside = hanging indent.
ul does not accept margin, padding. Use <li> to change distance from bullet to text. */
ol{display:inline;list-style-type:decimal;list-style-position:outside}
/* To begin at a specified number use <li value="5">, not <ol start="5"> which is deprecated. */
li{padding-left:0px;margin-left:5%}
/* This is essential. Margin indents bullets;
padding increases gap between bullet and text. */