<link href="mindprod.css" type="text/css" rel="stylesheet" media="screen"> <link href="jdisplay.css" type="text/css" rel="stylesheet" media="screen"> <meta http-equiv="Content-Style-Type" content="text/css">This is the normal way to handle style sheets.
<!-- a mini style sheet embedded in the header --> <style type="text/css"> h2, h3 { font-family: Arial,Helvetica,sans-serif; } body { background: white; } pre, tt { color: #333333; } th { background: tan; } </style>Normally you use this technique to add to the standard style sheet styles that appear nowhere else but this page.
<span style="font-variant:small-caps;font-family:'Tiresias PCFont Z'"> This will show up in small caps.</span>
When you use embedded styles, you must use ' instead of " e.g.
<span class="frog">… </span>Note the there is no dot before frog when you used the tag, just when you define it.
<table class="gridmenu">and all the text in the table will use those defaults. You no longer use any of the traditional HTML tags in your <table commands such border="0" cellpadding="4" cellspacing="4".
To control the outer perimeter of the table you attach styles to table.gridmenu. To control the perimeter of the individual cells, you attach cells to table.gridmenu td.
You can define styles based on context, e.g. how a td renders differently inside a table or inside two or three levels of table. You can specify every imaginable combination of styles of the nestings.
Make sure you have all the combinations defined that you need.Click any ball to view the corresponding colour palette.
Look for websites that display this logo
and
study their html and their style sheets to learn how these tools are used in
practiced. I switched over the mindprod.com site
over to use them. You can specify styles that only take effect under special
nested conditions. You can override styles with more styles or with ordinary
HTML tags. There are currently two CSS standards, CSS1 and CSS2. CSS2 has many
more features, including the ability to specify different styles for display on
screen and for printing. It also allows you to include fonts with your document.
CSS is actually much easier to learn and much less work to apply than the old system. The philosophy is different. You don’t mix your style and text information. You put all your style thoughts in one place to be globally applied. You mark up your text with what flavour of thing each chunk of text is, not how it is to be painted. The biggest problem is you can make syntax errors, and nothing complains and nothing happens. E.g. it is color not foreground-colour. It is margin-left: 100px not left-margin: 100 px, font-size: 125% not size: +25%, padding-top: 6pt not top-padding: 6 pt.
// example of how you might attach font attributes to a tagging class. .bushsaid { background: transparent; color: #552500 /* dark brown*/; font-family: "Lucida Console",courier,"courier new",monospace; font-style: italic; font-weight: bold; }
Working from the inside out:
If you don’t have a rule around the item, just ignore the border and margin, and use the padding fields.
| CSS Padding and Border | Java Insets | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
| ||||||||||||||||||
| Beware, the CSS border and padding specifications are ordered clockwise:
top, right, bottom, left. You can help remember this by thinking CSS and clockwise both begin with C. |
Java Insets, in contrast, are ordered counter
clockwise:
top, left, bottom, right |
To adjust margins and padding you need to measure how far off they are. This is most easily done with a virtual ruler. If you just guess, you can spin your wheels for hours.
What happens when you have a margin around an element? Is the margin ignored or is the box indented when it occurs at the start of a line. Let’s find out:
box with 10px padding and 20px border
Oddly, the additional margin is honoured on the left, with the border indented 20px, but not on the top and bottom. What happens when two such boxes butt against each other. Is the margin considered a minimum approach distance where the separation would be 20px, or a inviolate additive force field where the distance is the sum, namely 40px? Let’s find out:
box with 10px padding and 20px borderanother box with 10px padding and 20px border
The margins are additive, the borders are separated by 40px.
/* text decoration */ .nounderline { text-decoration : none /* get rid of underline */; } .underline { text-decoration : underline /* underline */; }
| Possible values for the CSS position property | |
|---|---|
| position:static; | default positioning |
| position:relative; | relative to where the text would normally appear, controlled by the independent top, right, bottom and left properties which can be specified in various units including pixels, ems and percentages. Note, you don’t specify the offsets on the position property. They are specified on their own independent properties. |
| position:absolute; | means relative to the top left corner of the enclosing element. |
| position:fixed; | relative to the top left corner of the screen. For example, fixed is used for headings that don’t scroll while the rest of the document does. Use these in conjunction with width, height, min-width and min-height properties for many different effects. |
| position:auto; | asks the browser to compute the value so that the other properties are satisfied. |
float:left; float:right; and float:none; are yet another positioning tool. They do extreme positioning.
These tools let you rearrange text, so that it renders in a completely different order. For example, you can embed a span tag in a paragraph that puts a marker to the left of the beginning of the paragraph.
You can also do things like put the text to load an ad last on the page, but use absolute positioning to place it near the top of the page, effectively letting you design in layers. That way it will the lowest priority for rendering, but still be at the top of the page.
There is the related background-position: property, which can be contracted into the background: property. Default value: 0% 0% (x% y%). The first value is the horizontal position and the second value is the vertical. The top left corner is 0% 0%. The right bottom corner is 100% 100%. If you only specify one value, the other value will be 50%.
For integers 0,0, the first value is the horizontal position and the second value is the vertical. The top left corner is 0, 0. Units can be pixels (0px 0px) or any other CSS units. 0 must be written without units. All other values must have a unit. If you leave the unit out, you won’t get an error message. Your property will most likely be ignored.
| Possible values for the CSS background-position property | |||
|---|---|---|---|
| Position | Appearance on Cell | Appearance on Unpadded Text | Notes |
| background-position:top left; | style on cell <td | style on text <span | background image upper left corner aligns with upper left corner of the box. Note you specify the y positioner before the x positioner when you use words. |
| background-position:top center; | style on cell <td | style on text <span | background image is aligned with the top and centred. |
| background-position:top right; | style on cell <td | style on text <span | upper right |
| background-position:left center; | style on cell <td | style on text <span | middle left |
| background-position:center center; | style on cell <td | style on text <span | centred |
| background-position:right center; | style on cell <td | style on text <span | middle right |
| background-position:bottom left; | style on cell <td | style on text <span | bottom left |
| background-position:bottom center; | style on cell <td | style on text <span | bottom centre |
| background-position:bottom right; | style on cell <td | style on text <span | bottom right |
| background-position:0% 100%; | style on cell <td | style on text <span | order x, y. 0% means the upper left corner of the background image is positioned as far left or as far up as possible. 100% means as far right or as far down as possible. 50% in the middle. I have not experimented with numbers less than 0 or greater than 100. Don’t mix % with word values. |
| background-position:20px 10px; | style on cell <td | style on text <span | background image is positioned 5px to right of normal position and 10 px down. |
| background-position:-10px -5px; | style on cell <td | style on text <span | background image is positioned 5 px to left of normal position and 10 px up. |
There are four problems to solve when you use background images.
The Netscape 8.1 is much better. Internet Explorer too has many bugs. The one that annoys me the most is it ignores your style sheet entirely if you include a metatag like this:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-3">
Other bugs are it ignores min-height and it can’t render png images with transparent backgrounds correctly. Opera is relatively bug free in CSS, and is faster that Netscape and IE, but not all plug-ins work with it, and it has bugs in forms and JavaScript. You might consider using Opera to get your CSS working, then switch over to dodge the bugs in the other browsers.
Beware of background-color: inherit. It is not well supported, and can lead no strange behaviour like non-repeating elements that repeat just once.
All the major browsers ignore <col class= and all but opera ignore <col align=. Last revised 2007-04-27.
The Web Standards Acid test for CSS shows Opera to be perfectly in compliance, Sea Monkey and Netscape with minor probls, Firefox with serious problems and IE as hopeless.
Selector span.frog
<td><span class="frog">some text</span></td>is a quite different animal from selector td.frog
<td class="frog">some text</td>even when the span is inside a td.
Some styles will inherit, e.g. font-face, which will provide the default for td if applied to the enclosing table.
When I refer to an image in a style sheet e.g.
TopStyle is a program that lets you edit style sheets. It mainly just lists all the possible attributes and lets you fill in the ones you want for each style. You soon discover there are hundreds of possible attributes you can apply to a style. Further, you discover, that unlike HTML, you can apply any attribute to any tag, even tags like <a, <img and <applet. This makes CSS much more flexible than HTML.
You can, for example, fudge the way text and images align vertically together with the vertical-align attribute. You can add that to any style.
Don’t worry too much about understanding what all the style attributes mean. If you see something promising, try setting the attribute to all of its allowed values and look at the results. You will figure it out much faster than if you try to make sense of the lawyerly W3C specification prose. The trick is finding likely candidates in the overwhelming sea of possibilities, and remembering to try them at the table, row and cell level to see the varying effects.
The other thing to keep in mind is you must be brave and try out unlikely combinations. Coming from a standard HTML background, you may be too timid to try attributes you have traditionally associated with only one tag on another.
The orthogonality is most clear when you see the definitions of all the selectors in the W3C default CSS style sheet (which browsers don’t necessarily use.) You can see how the special behaviour of each tag is created simply by assigning the tag standard properties.
Sometimes this orthogonality will get you in trouble. For example, the bullets in unordered lists are, under-the-hood, really just a specialised background image. You may confuse your browser if you try to use both a background image and a bullet (or bullet image) on the same block of text.
/* here is how to avoid duplicating properties common to many classes */ .titlejgloss, .titlebgloss { /* add properties that apply to both classes */ } .titlejgloss { /* add properties that only apply to titlejgloss */ } .titlebgloss { /* add properties that only apply to titlebgloss */ }
The precedence goes like this:
| CSS Selector Examples | |
|---|---|
| Example | Meaning |
| td | means this rule applies to the contents between any <td>... </td> |
| .strawberry | means this rule applies to anything marked with class="strawberry" |
| td ul | means this rule applies to any <ul> nested inside a <td>, nested at any depth. |
| td>ul | means this rule applies to any <ul> immediately nested inside a <td>, in other words, a child. Unfortunately IE does not support this. |
| td.strawberry | means this rule applies to any <td class="strawberry">. |
| p + table | means this rule applies to any <table preceded by a <p>. I don’t know of any browsers that support this yet. |
| div * li | means this rules applies only to a <li> at least grandchild levels deep inside the <div>. If it is a direct child, it does not count. |
| a.button:link | means use this rule for unvisited links coded with <a class="button" href=… |
| a.button:visited | means use this rule for visited links coded with <a class="button" href=... |
| a.button:active | means use this rule for active links coded with <a class="button" href=... An active link is the one you just clicked. |
| a.button:hover | means use this rule for the link the cursor is hovering over with <a class="button" href=... |
| a[href] | means use this rule for any <a href="xx"> text</a> |
| table.strawberry td a:link | Means this rule only applies to unvisited links inside <td>
inside tables with class="strawberry".
Just plain table.strawberry a:link will not work
because the links are not immediately inside the <table>
but nested a level deeper inside <td> tags.
You might use this selector to turn off underlining by combining it with this
rule:
{
/* turn off underline */ text-decoration : none; } |
| table.strawberry td a:visited img | Means this rule only applies to visited <img
links inside <td> inside tables with class="strawberry".
You might use this selector to turn off the red/blue box around an image link by
combining it with this rule:
{
/* turn off border around image */ border : none; } |
/* markup to use this rule: <p class="fancy">Here is a basic drop cap:</p> */ p.fancy:first-letter { font-size:200%; vertical-align:-.4em; }
| Tool | Cost
|
Notes |
|---|---|---|
| Rapid CSS | Has a trial. Has nice spell checker. Seems to be an ordinary text editor with syntax highlighting. Works much like TopStyle, with an even more convenient layout. You can jump to style on in the left panel, and change its fields on the right, and see the text in the middle. Crashed every time I attempted to use the internal preview panel. The preview in a browser works once you configure your browser locations. | |
| CSS edit | I have never used it. Has a trial. For the mac. | |
| Style Studio | It failed to install on Windows Vista. The author said he is working on a Vista-compatible version. Has a trial. | |
| StyleMaster | Has a trial demo. It has the 3-windows layout where you select the style on the left, see the text on the right and edit with dialogs on the left. It crashed when I tried the validator. It previews using various web browsers you can configure. It does at tiny bit of previewing e.g. colour and font in the left window style selector. It will scan your site to look for orphan (unused) styles. The scan is quite slow compared with TopStyle. It failed to display the results. It uses an external web validator. It has a convenient help window to find out about all the css keywords. With the menu or with keystrokes you can invoke all manner of mini-editors. The help is implemented as HTML displayed in a spawned browser, so it is slow to start and without the usual search features. Has both a Windows and Mac version. | |
| TopStyle | What I use now. Does not work under Vista. |
Even when there is no bug, there is no way grabbing the browser by the shoulders and saying “why did you do that?” CSS is inscrutable.
![]() |
recommend book⇒CSS Cookbook | |||||||||||||||||||||
| paperback | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ISBN10: | 0-596-00576-8 | |||||||||||||||||||||
| ISBN13: | 978-0-596-00576-4 | |||||||||||||||||||||
| publisher: | O’Reilly | |||||||||||||||||||||
| published: | 2004-08 | |||||||||||||||||||||
| by: | Christopher Schmitt | |||||||||||||||||||||
| Most people learn most easily from looking an working examples with some explanation, and not to much theory. | ||||||||||||||||||||||
| ||||||||||||||||||||||
![]() |
recommend book⇒Cascading Style Sheets: The Definitive Guide, 2nd Edition | |||||||||||||||||||||
| paperback | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ISBN10: | 0-596-00525-3 | |||||||||||||||||||||
| ISBN13: | 978-0-596-00525-2 | |||||||||||||||||||||
| publisher: | O’Reilly | |||||||||||||||||||||
| published: | 2004-01-01 | |||||||||||||||||||||
| by: | Eric A. Meyer | |||||||||||||||||||||
| Also covers faulty and spotty browser support to help you deal with compatibility issues. Make sure you get the second edition. The first was published in 2000 and is highly concerned with limitations of browsers of that time. The problem with this book is it belabours the obvious. You wade through pages and pages of dummy-level repetitive explanation, to find the nuggets of the unexpected which are not marked in any way. | ||||||||||||||||||||||
| ||||||||||||||||||||||
![]() |
recommend book⇒The Zen of CSS Design : Visual Enlightenment for the Web (Voices That Matter) | |||||||||||||||||
| paperback | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ISBN10: | 0-321-30347-4 | |||||||||||||||||
| ISBN13: | 978-0-321-30347-9 | |||||||||||||||||
| publisher: | Peachpit Press | |||||||||||||||||
| published: | 2005-02-27 | |||||||||||||||||
| by: | Dave Shea, Molly E. Holzschlag | |||||||||||||||||
| The author maintains the website www.csszengarden.com, where you can check out his sense of aesthetics. The impressive tricks he manages require extensive tweaking of the markup. Purists feel that is cheating. Markup should not have to be modified, only the style sheets. | ||||||||||||||||||
| ||||||||||||||||||
![]() |
recommend book⇒Beginning CSS : Cascading Style Sheets for Web Design (Programmer to Programmer) | |||||||||||||||||
| paperback | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ISBN10: | 0-7645-7642-9 | |||||||||||||||||
| ISBN13: | 978-0-7645-7642-3 | |||||||||||||||||
| publisher: | Wrox | |||||||||||||||||
| published: | 2004-12-24 | |||||||||||||||||
| by: | Richard York | |||||||||||||||||
| Beginner’s book that teaches by examples. | ||||||||||||||||||
| ||||||||||||||||||
![]() |
recommend book⇒Web Standards Solutions: The Markup and Style Handbook (Pioneering Series) | |||||||||||||||||
| paperback | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ISBN10: | 1-59059-381-2 | |||||||||||||||||
| ISBN13: | 978-1-59059-381-3 | |||||||||||||||||
| publisher: | friends of ED | |||||||||||||||||
| published: | 2004-06-07 | |||||||||||||||||
| by: | Dan Cederholm | |||||||||||||||||
| Handles both HTML and CSS focussing on following standards to keep the web tidy. | ||||||||||||||||||
| ||||||||||||||||||
![]() |
recommend book⇒Core CSS: Cascading Style Sheets, second edition | |||||||||||||||||
| paperback | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ISBN10: | 0-13-009278-9 | |||||||||||||||||
| ISBN13: | 978-0-13-009278-6 | |||||||||||||||||
| publisher: | Prentice Hall | |||||||||||||||||
| published: | 2003-10-03 | |||||||||||||||||
| by: | Keith Schengili-Roberts | |||||||||||||||||
| Not recommended. The author spends pages and pages belabouring the obvious and hops over anything the least bit difficult with almost no explanation whatsoever. The book meticulously documents what works and what does not in a number of obsolete browsers. | ||||||||||||||||||
| ||||||||||||||||||
![]() |
and suggestions to improve this page to Roedy Green : | ||
| Canadian Mind Products | |||
| mindprod.com IP:[65.110.21.43] | |||
| Your face IP:[38.103.63.16] | The information on this page is for non-military use only. | ||
| You are visitor number 67,892. | Military use includes use by defence contractors. | ||
| You can get a fresh copy of this page from: | or possibly from your local J: drive (Java virtual drive/Mindprod website mirror) | ||
| http://mindprod.com/jgloss/css.html | J:\mindprod\jgloss\css.html | ||