The Craftsman four-square firmly rejected the highly asymmetric designs of the Queen Anne period that preceded it.

Well, most of them did. This sort-of-four-square Craftsman home embraces the asymmetries of the Queen Anne (1890s) period. It also shows the Craftsman hipped roof, hipped dormers, porch roof supported by strong, square columns: all Craftsman characteristics.

This is a large home, presumably built for a prosperous businessman. It shows great strength, but at the same time it has some fun.

Craftsman four-square, embracing Queen Anne asymmetries, Warwick, NY, c. 1920.

Craftsman four-square, but very unsquare.

Edges to Rubies The Complete SketchUp Tutorial


The axes box in the Lumberman WebDialog.

Chapter 18—HTML and CSS

You cannot build WebDialog interfaces to your Rubies if you do not know some HTML, HyperText Markup Language, and CSS, Cascading Style Sheets. This chapter will get you started. Google will find answers to more detailed questions.

HTML, Really Fast!

We'll begin with HTML, which is really a set of markup tags, not a language.

Create a test file. It should contain this HTML:

<!-- /r/t.html - html test file -->

<html>
	<head>
		<title>HTML Tests</title>
	</head>
	
	<body>
	
	</body>
</html>

<!-- end of /r/t.html -->

You can see four important things here:

  1. <!-- HTML comments are written this way. -->
  2. HTML is written between <html> and </html> tags. (At least it should be. Browsers include anything above the <html> tag and anything below the </html> tag, too.
  3. There are two tag-delimited sections in most HTML files: <head> and <body>.
Save this in a directory you create for its convenience. Mine's in /r/t.html. In your browser (Opera is best for PC testing, Safari's fine on Mac) open this page in a new tab. You'll see your title in the tab. (WebDialogs don't show titles. You won't need one.) (P.S. Opera aggressively caches graphics. If you need to swap graphics, switch to Firefox. Return to Opera when you get to JavaScript testing.)

Your WebDialog on the PC will run under MSIE but that will regularly crash your computer during development. Do just your final tests with MSIE.

From here on you'll see a long table with tags in the left side, the results of using those tags on the right. Type interesting variations on the tags into the body section of your HTML. Save. Reload in your browser. (Arrange editor and browser so you can easily click the browser's Reload button after you click the editor's Save button.) Again: you won't learn HTML by reading about it. You'll learn HTML by typing it. Good luck!

Bold and Italic.
This is plain text.
<b>This is bold text.</b>
<i> This is italic text. </i>
<b><i>This is bold, italic text. </i> </b>
This is plain text. This is bold text. This is italic text. This is bold, italic text.
Break and Paragraph
This is one line.
This looks like another line.
Throw in a break to force a new line.<br>
Use a paragraph to get paragraph space.<p>
Like this one!
This is one line. This looks like another line. Throw in a break to force a new line.
Use a paragraph to get paragraph space.

Like this one!

Headers
<h1>Header 1</h1>
<h2>Header 2</h2>
<h3>Header 3</h3>
<h4>Header 4</h4>
<h5>Header 5</h5>
<h6>Header 6</h6>

Header 1

Header 2

Header 3

Header 4

Header 5
Header 6
Center
<center>
This text<br>
is centered.
</center>
This text
is centered.
Attributes Some tags have additional modifiers, called "attributes." According to HTML's governing body, all values assigned to attributes are strings and in HTML strings must be in quotes. (They're pretending that HTML is a language, which it isn't.) According to all browsers a consecutive string of non-blanks following the attribute= is a string, with or without quotes. (Browsers think that lots of web pages are created by amateurs, which is true.) If you want to include blanks in the value passed to an attribute you must enclose it in quotes. Otherwise, it's up to you.
Horizontal Rule
<hr>
<hr size=3px>
<hr align=center width=80%>



Font
Normal text.
<font size=+1> Bigger text. </font>
<font size=-1> Smaller text. </font>
<font color=red> Red text. </font>
<font size=-1 face=monospace>Monospaced smaller text.</font>
Normal text. Bigger text. Smaller text. Red text. Monospaced smaller text.
Subscript, Superscript
Subscript 1<sub>1</sub>
Superscript 2<sup>2</sup>
Subscript 11 Superscript 22
Image
The "<img>" tag has no end tag. Simplest image: <img src='snoozy-kitty.gif'>. Problem! MSIE defaults to 1px border. Everyone else defaults to 0px. Always specify border. alt attribute: used by visually impaired. (Google's web crawlers are visually impaired.) Used by MSIE for tooltip unless title is present. Not used for tooltip by other browsers. You may set height and width, but it's best to use image software to get the right height and width in the file. Model:
<img
    alt='Picture of tiger-striped kitten sleeping.'
    border=0
    src='snoozy-kitty.jpg'
    title="That's our Emma, sound asleep!"
>
Lists
<ul>
	<li>Unordered</li>
	<li>List</li>
</ul>
<ol>
	<li>Ordered (numbered)</li>
	<li>List</li>
</ol>

<ol type=I>
    <li> Main 1
        <ol type=A>
            <li> Major A
                <ol type=a>
                    <li>minor 1</li>
                    <li>minor 2</li>
                </ol>
            </li>
            <li>Major B</li>
        </ol>
    </li>
    <li> Main 2</li>
</ol>

  • Unordered
  • List
  1. Ordered (numbered)
  2. List
  1. Main 1
    1. Major A
      1. minor 1
      2. minor 2
    2. Major B
  2. Main 2
There's a trick to making
nested lists. Start this way:
  Then move "Main 1"'s
"</li>" out of the way:
  Then add in the nested list,
but only to one level.
<ol type=I>
    <li>Main 1</li>
    <li>Main 2</li>
</ol>
        
<ol type=I>
    <li>Main 1
    </li>
    <li>Main 2</li>
</ol>
        
<ol type=I>
    <li>Main 1
        <ol type=A>
            <li>Major A</li>
            <li>Major B</li>
        </ol>
    </li>
    <li>Main 2</li>
</ol>
        
Repeat as needed, working one level at a time.
Links
Link to another page, this site: <a href='another_page.html'>another page</a>

Naming a location in this page: <a name='big_deal'></a>

Link to named location, this page: <a href='#big_deal'>another section</a>

Link to named location, other page, this site: <a href='other_page.html#big_deal'>other section in other page</a>

Link to page, different site: <a href='http://another_site.com/page.html'>another site</a>

Link to named location, different site: <a href='http://other.org/page.html#loc'>specific place in another site</a>

Table: Basics
<table align=center border=1 cellpadding=3>
    <tr>
        <td> Row 1, Col 1 </td>
        <td> Row 1, Col 2 </td>
    </tr>
    <tr>
        <td> Row 2, Col 1 </td>
        <td> Row 2, Col 2 </td>
    </tr>
</table>
(td = Table Datum)
Row 1, Col 1 Row 1, Col 2
Row 2, Col 1 Row 2, Col 2
Table: Captions and Column Headings
<table align=left border=1 cellpadding=3>
    <caption> <h3> Caption </h3> </caption>
    <tr>
        <th> Col 1 </th>
        <th> Col 2 </th>
    </tr>
    <tr>
        <td> Row 1, Col 1 </td>
        <td> Row 1, Col 2 </td>
    </tr>
    <tr>
        <td> Row 2, Col 1 </td>
        <td> Row 2, Col 2 </td>
    </tr>
</table>

Caption

Col 1 Col 2
Row 1, Col 1 Row 1, Col 2
Row 2, Col 1 Row 2, Col 2
Table: Cellpadding and Cellspacing
<table align=center border=1 cellpadding=10>
    <tr>
        <td> Row 1, Col 1 </td>
        <td> Row 1, Col 2 </td>
    </tr>
    <tr>
        <td> Row 2, Col 1 </td>
        <td> Row 2, Col 2 </td>
    </tr>
</table> 
<p>
<table align=right border=1 cellspacing=10>
    <tr>
        <td> Row 1, Col 1 </td>
        <td> Row 1, Col 2 </td>
    </tr>
    <tr>
        <td> Row 2, Col 1 </td>
        <td> Row 2, Col 2 </td>
    </tr>
</table> 
Row 1, Col 1 Row 1, Col 2
Row 2, Col 1 Row 2, Col 2

Row 1, Col 1 Row 1, Col 2
Row 2, Col 1 Row 2, Col 2

Table: Colspan and Rowspan
<table align=center border=1 cellpadding=3>
    <tr>
        <td rowspan=2> Row 1, Col 1 </td>
        <td align=center colspan=2> Row 1, Col 2 </td>
    </tr>
    <tr>
        <td> Row 2, Col 2 </td>
        <td> Row 2, Col 3 </td>
    </tr>
</table> 
Row 1, Col 1 Row 1, Col 2
Row 2, Col 2 Row 2, Col 3

The Lumberman Project

Administrative note.

If you are truly hardcore, you'll create all your own graphics. I applaud you. Others may want to go to the

Tutorial Companion Packages

download page. The Lumberman package includes all the graphics as well as finished versions of the Ruby, HTML and JavaScript. Refer to my code if you get totally stuck. If you get yours working without looking at my code, you're really mastering this stuff. I'll forgive you for stealing the graphics.

Think you're getting this? I hope so. Time to meet the Lumberman project. This is a lumberyard where The SketchUp modeler can go to get a custom-cut board. Here's what the WebDialog looks like:

Screenshot, Lumberman WebDialog

I was very pleased with the way this came out. I don't think any user will have any problem getting the lumber they want cut to size. Simplicity in the UI is one of the hardest things to achieve.

Consider this. The user selects "blue" for the length axis. The radio buttons are adjusted to read "red" and "green", neither is checked. The image is replaced with one that says "Width axis?". The user chooses a width axis. The text following "Thickness axis" is adjusted to the one remaining axis. The picture swaps in a picture of a board on the axes specified. The programmer works hard to get JavaScript to do all this. The users don't work hard to get the boards they want. That's the way it should be.

We'll use this WebDialog in this chapter to show you HTML tips and tricks. We'll use it again in the next chapter for JavaScript tips and tricks. On to the HTML.

This being the 21st century you should lay that table out with CSS. Separates content from format, they say. They have a good point if you need to think about the visually impaired. Of course, if you are writing SketchUp WebDialogs, you are working on Rubies for sighted people, so this isn't a relevant concern. Let's use the twentieth century technique of using tables for layout.

Here's the table-based portion of that WebDialog with every table's border attribute set to 1:

Screenshot, Lumberman WebDialog w/borders

Your job is to create the HTML for this form. For now, just say "dropdown widget" instead of actually trying to get the right element. We'll go for real widgets after we cover HTML forms. Begin your own lumberman.html with a copy of this skeleton:

<!-- /r/lumberman.html - models boards custom cut -->
<!-- Copyright 2009, Martin Rinehart -->

<html>
    <head>
        <title>Name: Product</title>
        <style type='text/css'>
            body { font-family:sans-serif; }
            .button { font-size:1.5em; color:#000044;}
            .material { padding:2px; }
            .whiter { background-color:#f0f0ff; }
            .bluer  { background-color:#d0d0ff; }
        </style>
    </head>
<body>

<center>
<hr width=80%>
<h1> Name: Product </h1>
<h2> Trustworthiness </h2>
<p>
<h3> memorable slogan </h3>
<hr width=80%>
</center>

Save the file and open it in your favorite browser. Think up and add something appropriate for making boards for the name, product, trustworthiness and slogan. You've finished the easy part.

Tables within tables and tables within tables within tables are devilish, until you learn the trick.

Begin with the big table. Begin every table with border=1. (Without content it will be a small table, but you'll fatten it up as you go.) Put just a word or two in each TD.:

<table border=1> <!-- you'll need to add attributes -->
    <tr>
        <td> image </td>
        <td> axes stuff </td>
        <td> lumber size</td>
        <td> length and materials </td>
    </tr>
    <tr> <td colspan=4> 
        buttons
    </td>  </tr>
</table>   

Take a look at this much. Fix anything that's broken. Add table attributes. Look/fix/add until you're happy.

Now the trick: Start your first table within a table, the one for picking axes, below the big table. Not inside the big table, outside and below it. It should look something like this:

<table border=1>
    <tr>
        <td colspan=2>
            <b>Length axis:</b> dropdown widget
        </td>
    </tr>
    <tr>
        <td>
            <b>Width axis:</b>
        </td>
        <td>
            radio buttons
        </td>
    </tr>
    <tr>
        <td>
            <b>Thickness axis:</b> variable text
        </td>
    </tr>
</table>

On your own, now, the other tables: one below the other. Get them all happy on their own. Put the length table and the materials table inside their immediate container (the one that you'll eventually put into the big table).

Hint: for buttons that at least look like buttons, use <button>Geometry</button>.

Save! Save again (under another name, of course)!

Now, very carefully, copy your nesting tables into the appropriate parts of the big table. Expecting to get it right on the first try is not realistic. Work slowly, save after each smaller table becomes part of the big table.

Got it right? Looking good? Congratulations. You must be learning HTML.

More HTML

Back to your tester and your study of HTML. Our last topic is forms. You're just two topics away from forms.

  
Colors
HTML has some named colors. It has far too many to remember, far too few to get exactly what you want. Forget them. Use the hexadecimal color spec.

Colors are specified with #rrggbb, a "#" followed by six hex digits. The first two digits specify the amount of red. The next two specify the amount of green. The last two specify the amount of blue. Hexadecimal digits are: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f. (You may use capital letters, but why not go with the ones that are easier to type?)

Red #000000 #220000 #440000 #660000 #880000 #aa0000 #cc0000 #ee0000 #ff0000
Green #000000 #002200 #004400 #006600 #008800 #00aa00 #00cc00 #00ee00 #00ff00
Blue #000000 #000022 #000044 #000066 #000088 #0000aa #0000cc #0000ee #0000ff
RedGreen #000000 #222200 #444400 #666600 #888800 #aaaa00 #cccc00 #eeee00 #ffff00
GreenBlue #000000 #002222 #004444 #006666 #008888 #00aaaa #00cccc #00eeee #00ffff
BlueRed #000000 #220022 #440044 #660066 #880088 #aa00aa #cc00cc #ee00ee #ff00ff
RedGreen + Blue #ffff00 #ffff22 #ffff44 #ffff66 #ffff88 #ffffaa #ffffcc #ffffee #ffffff
GreenBlue + Red #00ffff #22ffff #44ffff #66ffff #88ffff #aaffff #ccffff #eeffff #ffffff
BlueRed + Green #ff00ff #ff22ff #ff44ff #ff66ff #ff88ff #ffaaff #ffccff #ffeeff #ffffff

Fade 1 #ffffff #fffffa #ffffeb #ffffe6 #ffffe1 #ffffda #ffffd5 #ffffd0 #ffffcb #ffffc6 #ffffc1 #ffffbb #ffffb5
Fade 2 #fffcc7 #fff0ca #ffedcd #ffead0 #ffe8dc #ffe5df #ffe2e2 #ffdfe5 #ffdce8 #ffd0ea #ffcded #ffcaf0 #ffc7fc

Character Entities ampersand, name, semicolon (no spaces)
&copy;=©, &reg;=®, &trade;=™, &cent;=¢, &euro;=€, &pound;=£, &yen;=¥
&iquest;=¿, &sect;=§, &para;=¶, &amp;=&, &lt=<, &nbsp;= (non-breaking space)

Any of these: A a E e I i O o U u Y y
Combine with any of these: acute circ grave, uml
Examples: &Ouml;=Ö, &eacute;=é, &Egrave;=È, &icirc;=î

&Alpha;, &Beta;, &Gamma; ... = Α, Β, Γ, ...
&alpha, &beta, &gamma ... = α, β, γ, ...

HTML Forms
Buttons
<form> <input type=button value='Simple Button' onclick='JavaScript:alert("Simple Button clicked")'> </form>

<button onclick='alert("Fancy Button clicked")'> <font size=+3 color=#ff00ff> Fancy Button </font> <br> Click Me, Please </button>

Other Input Types
<form>

<input id='cbox' type=checkbox name=cbox onclick='alert( "sample checkbox is " + (document.getElementById("cbox").checked ? "checked" : "cleared") )'> sample checkbox <p>

File: <input type=file>¹<p>

password: <input type=password><p>

<input type=radio name=rset value="C"> Columbian <br>
<input type=radio name=rset value="H" checked> Hawaiian <br>
<input type=radio name=rset value="K"> Kenyan <p>

<input type=reset><p>

input type=text: <input type=text value='default'><p>

input type=duhm: <input type=text size=40 maxlength=3><p>

sample checkbox

File:

password:

Columbian
Hawaiian
Kenyan

input type=text:

input type=duhm:

¹Serious problem re <input type=file>: For security reasons, JavaScript is not allowed access to the path. You can see it. Your user can select it and see it. Your program can't see it. In Ruby, use UI.openpanel() or UI.savepanel() to let the user select a file.
Textareas
<textarea cols=20 rows=3>Default text</textarea> <p>

<textarea cols=40 rows=5 readonly> Another attribute is "wrap". It may be "wrap=hard" (carriage returns inserted), "wrap=soft" (wrapped, but returns not inserted) or "wrap=off" (leave it up to user).</textarea> <p>

<textarea cols=20 rows=2 disabled>Disabled textarea</textarea>

Select
<select>
	<option value='veg1'>vegan
	<option value='veg2'>vegatarian
	<option value='pesc'>pescetarian
	<option value='omni'>omnivore
</select>
<p>

<select multiple size=5> <option value='APL'>APL <option value='assembler'>assembler <option value='Basic'>Basic <option value='C'>C <option value='C++'>C++ <option value='dBASE'>dBASE <option value='Fortran'>Fortran <option value='Java'>Java <option value='JavaScript'>JavaScript <option value='Perl'>Perl <option value='PHP'>PHP <option value='PL1'>PL/1 <option value='Python'>Python <option value='Ruby'>Ruby </select>

In HTML, many elements can contain many other elements. The list example showed ordered lists within other lists. For a clickable picture, put an <img> inside <a href = '...'> <img...> </a>.

Now you should know enough to finish the Lumberman's HTML. Stick in those widgets. You'll need JavaScript to hook them all up, but for now, you should be happy with HTML that drops down when you click a dropdown.

We skipped two important HTML tags, <div> and <span> as they are almost useless without CSS styles. We'll get to these tags soon.

Further activity:

For a slower, more thorough tutorial, try my www.easyHTMLtutorial.com.

For a big poster (that substitutes for a perfect memory) of all this and more, Martin Rinehart's HTML poster.

Connecting CSS Styles to HTML

If you cannot connect your styles to your HTML, styles are useless. If you do not have any styles to connect, connecting styles is useless. Catch 22.

So, here's your first style and value: background-color: #ff0000;. That sets the background color of an element to pure red. Pure red is overkill, unless you are trying to test your style/HTML connections, where it is perfect.

Styles can be placed in separate CSS files. CSS files can link to other CSS files, hence Cascading Style Sheets. For WebDialog programming separate CSS files are probably a bad idea. Styles can also be declared within tags and in the <head> section of your HTML. I'll introduce you to both, starting with styles in the tag.

A span is an inline element in your HTML. (The "inline" elements—words, links, images—flow across the page, space permitting. The "block" elements—headings, tables, lists, paragraphs, ...— normally flow one above the other.)

Test this span code: <span bgcolor=red> test span </span>

It doesn't work. There is no bgcolor attribute for the <span> tag. Any element can have a style tag, which means than any style can be applied to any element.

Test this span code: <span style='background-color: #ff0000;'>test span</span>

That gives you a bright red test span.

Suppose you had a color that you wanted to apply regularly, such as the green that colors code, here. Suppose you had multiple styles to apply to a single span, as the code here is also shown in a monospaced font, slightly larger size, etc. Baking in your styles in every tag is possible, but it's not the easy way. Creating CSS style classes in your page's <head> section is the easy way:

    <head>
         ...
        <style type = 'text/css'>
            .code_class { 
                background-color: #d0ffd0; 
                font-family: monospace;
                font-size: 1.2em;
            }
        </style>
    </head>

Now you can attach that class to any tag. This will attach it to a span: <span class='code_class'>. There are other ways to connect styles in the <head> section to elements in the <body> section and we'll meet one of them shortly. This one will handle most of your WebDialog needs. Note: the class name is preceded with a period in the <style> section of the <head> section. That tells your page "this is a CSS class specification". The period does not reappear after class=.

Real style sections typically have multiple styles per class and multiple classes:

        <style type='text/css'>
            .one_class {
                style-spec1: value1;
                style-spec2: value2
            }
            .another {
                style-spec3: value3;
                ...
            }
            ...
        </style>

The <div> Tag

A <div> is a block element, as a span is an inline element. The big green blocks in the previous section where styles are defined in the header? They are <div class='code'> at their tops, and, of course </div> at their bottoms.

The Styles Hierarchy

More explicit styles override less explicit styles. <div class='code' style='background-color:#ff0000'> will be bright red, regardless of what the code class says.

All the Styles You Need to Know

Google for a "CSS reference." Pick one you like and make it your friend.

Positioning: if you try position:absolute; you are definitely on your own. Good luck! Some of the best stuff on the web uses absolute positioning.

Tables: laying out a web page using tables, borders off so you don't see them, was the way it was done before CSS. Please don't tell, but it's still the way I lay things out.

The default font size in forms is absurdly small. The following four additions to the <style> section in the page header will bring the form's fonts up to whatever size the user prefers for text:

        <style type='text/css'>
            ...
            button { font-size:1em; }
            input { font-size:1em; }
            select { font-size:1em; }
            textarea { font-size:1em; }
        </style>
Did you note that these are not classes? (Classes are prefixed with a dot in the <style> section. The dot disappears in the class= attribute assignment.) If you use a tag name, every occurence of that tag is given the style(s) you specify. Here's another one I use a lot: body { font-family: FreeSans, Arial, sans-serif; }.

What other styles do I use for WebDialogs? Actually, mostly one: background-color. I'm also using display. (display:none makes things disappear. display:block makes them reappear.) If you want to experiment a bit, try padding and margin. And experiment with border but use it like fresh-ground black pepper: a little is good; a lot is awful.

Now go back and look at the styles I defined. Should any of them apply to what you've built so far? (Hint: I don't define styles for a giggle.) Notice how I used "bluer" and "whiter" to separate parts of the dialog? Go for it!

HTML, CSS and the beginning of a serious WebDialog! Congratulations. We'll get that WebDialog working (and you'll get some JavaScript working) in Chapter 19.


The documentation frameset. View of apartment contents. Screenshot of JavaScript Console in operation.