Weitere ähnliche Inhalte Ähnlich wie Doing it in style - creating beautiful sites, the web standards way / WebDD / Reading / 3 February 2007 (20) Mehr von Patrick Lauke (20) Kürzlich hochgeladen (20) Doing it in style - creating beautiful sites, the web standards way / WebDD / Reading / 3 February 20071. Doing it in style
CREATING BEAUTIFUL SITES, THE WEB STANDARDS WAY
Patrick H. Lauke / WebDD / 3 February 2007
4. Web standard tenets
Boil down to three things:
●
Separation of content and presentation
●
Valid (published grammar)
●
Semantic markup/code
6. Web standards and aesthetics?
“You can't make good looking sites with web
standards...”
13. Traditional “old school” way
Choice of markup purely down to their look
●
<h1> is too big ... I'll use <h4> instead
●
<blockquote> to indent
●
More space between paragraphs ... add a few
<p></p>
14. Traditional “old school” way
...then sprinkle presentational markup on top
●
forget <h4> ... <p><font size="+3"
color="ffffff><b>...</b></font></p>
● <p>this is <b>important</b>.</p>
15. Web standards process
Distinct tasks:
●
Mark up content in most appropriate elements -
convey meaning, not look
●
Apply styling (override browser defaults)
Model, View, Controller (MVC) parallels?
16. Why web standards
Some advantages:
●
Lighter code
●
Easier to maintain
●
Easier to change look/feel
●
Multiple output media
●
Accessibility
●
SEO
18. New technology, old habits
<p><font size="+3" color="ffffff">...</font></p>
<p><span style="font-size: 200%; color:
#ffffff">...</span></p>
<p style="font-size: 200%; color:
#ffffff">...</p>
24. Classitis – the “labelmaker” approach
.nav { color: green; }
<ul>
<li><a href="..." class="nav"> ... </a></li>
<li><a href="..." class="nav"> ... </a></li>
<li><a href="..." class="nav"> ... </a></li>
<li><a href="..." class="nav"> ... </a></li>
<li><a href="..." class="nav"> ... </a></li>
</ul>
25. Classitis – cured
#nav a { color: green; }
<ul id="nav">
<li><a href="..."> ... </a></li>
<li><a href="..."> ... </a></li>
<li><a href="..."> ... </a></li>
<li><a href="..."> ... </a></li>
<li><a href="..."> ... </a></li>
</ul>
●
Be smart with your CSS
●
Use semantic structure to your advantage
26. Divitis – everything in neatly labelled boxes
<div id="header">
<h1>Patrick's rants</h1>
</div>
<div id="navigation">
<ul>...</ul>
</div>
<div id="footer">
<p>©2007 ... </p>
</div>
27. Divitis – cured
<h1 id="header">Patrick's rants</h1>
<ul id="navigation">...</ul>
<p id="footer">©2007 ... </p>
●
Knowledge about your content to simplify markup.
●
Not easy with generic template/CMS?
30. Tables (faked)
Misguided zealots go too far...
<div>
<div>
<span>First name</span>
<span>Last name</span>
</div>
<div>
<span>Patrick</span>
<span>Lauke</span>
</div>
...
</div>
31. Tables!
Not all tables are evil...
●
Tabular content (Excel spreadsheet)
●
Best way to define relationship
●
Accessibility
32. Explicit semantics of tables
<table>
<tr>
<td>Name</td>
<td>Phone</td>
<td>Email</td>
</tr>
<tr>
<td>Patrick H. Lauke</td>
<td>0161 2954779</td>
<td>p.h.lauke@salford.ac.uk</td>
</tr>
...
</table>
33. Explicit semantics of tables
<table>
<tr>
<th scope="col">Name</th>
<th scope="col">Phone</th>
<th scope="col">Email</th>
</tr>
<tr>
<th scope="row">Patrick H. Lauke</th>
<td>0161 2954779</td>
<td>p.h.lauke@salford.ac.uk</td>
</tr>
...
</table>
34. Explicit semantics of tables
<table>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Phone</th>
<th scope="col">Email</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Patrick H. Lauke</td>
<td>0161 2954779</td>
<td>p.h.lauke@salford.ac.uk</td>
</tr>
...
</tbody>
35. Explicit semantics and styling
With thead/tbody easy to nicely style table
thead { background-color: #444; color: #fff; }
36. Explicit semantics and styling
Style th differently in table body
thead { background-color: #444; color: #fff; }
tbody th { font-weight: normal;
text-align: left;
}
37. Explicit semantics and styling
Underline each row
table { border-collapse: collapse; }
thead { background-color: #444; color: #fff; }
tbody th { font-weight: normal;
text-align: left;
}
tbody tr th,
tbody tr td { border-bottom: 1px #444 solid; }
38. Explicit semantics and styling
Headless table
table { border-collapse: collapse; }
thead { position: absolute; top: 0; left: -999em;
}
tbody th { font-weight: normal;
text-align: left;
}
tbody tr th,
tbody tr td { border-bottom: 1px #444 solid; }
...but IE doesn't like that...
39. Explicit semantics and styling
Headless table (even in IE)
table { border-collapse: collapse; }
thead,
thead tr { position: absolute; top: 0; left:
-999em; }
tbody th { font-weight: normal;
text-align: left;
}
tbody tr th,
tbody tr td { border-bottom: 1px #444 solid; }
42. “Fluff” images via CSS
If only decorative...
●
Decorative = presentation
●
Add images as non-repeating CSS backgrounds
46. “Fluff” images
Also works for inline elements
<p>See our <a href=""><img src="qt.gif" alt=""
... /> quicktime video</a> for more
information.</p>
47. “Fluff” images
<p>See our <a href="" class="qt">quicktime
video</a> for more information.</p>
a.qt { background: url(qt.gif)
no-repeat left center;
padding-left: 50px;
}
Beware of line-height, min-height won't work
48. Softening up boxes
Same principle, but for different purpose (“rounded
boxes”)
<blockquote><p>...</p></blockquote>
blockquote { color: #fff;
background-color: #73aeb5;
}
50. Softening up boxes
Apply image flush to corner
<blockquote><p>...</p></blockquote>
blockquote { color: #fff;
background: #73aeb5 url(corner.gif)
no-repeat left top;
}
51. Softening up boxes
More padding
<blockquote><p>...</p></blockquote>
blockquote { color: #fff;
background: #73aeb5 url(corner.gif)
no-repeat left top;
padding: 20px;
}
52. Softening up boxes
Changing box colour
<blockquote><p>...</p></blockquote>
blockquote { color: #fff;
background: #f77921 url(corner.gif)
no-repeat left top;
padding: 20px;
}
54. Softening up boxes
Naïve approach
<blockquote><p>...</p></blockquote>
blockquote { padding: 10px 20px 40px 20px;
width: 210px;
color: #333;
background: url(bigquote.gif)
no-repeat left top;
}
56. Softening up boxes
“Sliding doors”
<blockquote><p>...</p></blockquote>
blockquote { padding: 10px 20px 40px 20px;
width: 210px;
color: #333;
background: url(quote-top.gif)
no-repeat left top;
}
blockquote p { background: url(quote-bottom.gif)
no-repeat left bottom;
}
61. Image replacement
Wrap text in a span, apply background image
<h1><span>Heading</span></h1>
h1 { width: 350px; height: 75px;
padding: 0;
background: url(heading.gif)
no-repeat left top;
}
62. Image replacement
Hide the span
<h1><span>Heading</span></h1>
h1 { width: 350px; height: 75px;
padding: 0;
background: url(heading.gif)
no-repeat left top;
}
h1 span { display: block; position: absolute;
top: 0; left: -999em;
}
63. Image replacement
Taking it further: more than just a heading
<div id="header">
<h1>Heading</h1>
<h2>Subheading</h2> ...
</div>
#header * { display: block; position: absolute;
top: 0; left: -999em;
}
#header { ... }
65. Image replacement issues
From accessibility point of view:
●
Images off / CSS on
●
Text resizing / zoom
Multiple (unskilled/WYSIWYG) authors?
Backgrounds don't normally print
66. Image replacement trick?
Replacing an image with another image
<h1><img src="logo_bw.png" ... /></h1>
@media screen {
h1 { ...
background: url(logo_colour.jpg)
...
}
h1 img { ... /* off left */ ... }
}
Black/white logo for print, colour for on-screen
69. Forms – associating labels
Implicit:
<label>First name: <input type="text"
name="fname" /></label>
Explicit:
<label for="fname_id">First name:</label>
<input type="text" name="fname" id="fname_id" />
70. Forms – associating labels
“Belt & braces”
<label for="fname_id">First name:
<input type="text" name="fname" id="fname_id" />
</label>
72. Forms – grouping related controls
<p>What's your favourite colour?</p>
<label for="col_r">
<input type="radio" name="col" id="col_r"
value="red" /> Red</label>
<label for="col_g">
<input type="radio" name="col" id="col_g"
value="green" /> Green</label>
Radio buttons, checkboxes, form sections
73. Forms – grouping related controls
<fieldset>
<legend>What's your favourite colour?</legend>
<label for="col_r">
<input type="radio" name="col" id="col_r"
value="red" /> Red</label>
<label for="col_g">
<input type="radio" name="col" id="col_g"
value="green" /> Green</label>
</fieldset>
74. Forms – grouping related controls
<fieldset>
<legend>Billing address</legend>
...
</fieldset>
<fieldset>
<legend>Shipping address</legend>
...
</fieldset>
75. Forms – basic styling
<form ...>
<label>...</label>
<input />
<label>...</label>
<input />
<label>...</label>
<select> ... </select>
<input type="submit" ... />
</form>
label, input, select { display: block; }
76. Forms – basic styling
<form ...>
<div><label>...</label>
<input /></div>
<div><label>...</label>
<input /></div>
<div><label>...</label>
<select> ... </select></div>
<input type="submit" ... />
</form>
77. Forms – basic styling
<form ...>
<div><label>...</label>
<input /></div>
<div><label>...</label>
<input /></div>
<div><label>...</label>
<select> ... </select></div>
<input type="submit" ... />
</form>
div input, div select { float: right; }
78. Forms – basic styling
<form ...>
<div><label>...</label>
<input /></div>
<div><label>...</label>
<input /></div>
<div><label>...</label>
<select> ... </select></div>
<input type="submit" ... />
</form>
div label { float: left; }
div input, div select { float: right; }
79. Forms – basic styling
<form ...>
<div><label>...</label>
<input /></div>
<div><label>...</label>
<input /></div>
<div><label>...</label>
<select> ... </select></div>
<input type="submit" ... />
</form>
div label { float: left; clear: both; }
div input, div select { float: right; }
80. Forms – basic styling
<form ...>
<div><label>...</label>
<input /></div>
<div><label>...</label>
<input /></div>
<div><label>...</label>
<select> ... </select></div>
<input type="submit" ... />
</form>
div { height: 1.3em; }
div label { float: left; clear: both; }
div input, div select { float: right; }
81. Forms – basic styling
<form ...>
<div><label>...</label>
<input /></div>
<div><label>...</label>
<input /></div>
<div><label>...</label>
<select> ... </select></div>
<input type="submit" ... />
</form>
div { height: 1.3em; }
div input,
div select { position: absolute;
top: 0; left: 7em;
}
82. Forms – basic styling
<form ...>
<div><label>...</label>
<input /></div>
<div><label>...</label>
<input /></div>
<div><label>...</label>
<select> ... </select></div>
<input type="submit" ... />
</form>
div { height: 1.3em; position: relative; }
div input,
div select { position: absolute;
top: 0; left: 7em;
}
83. Forms – basic styling
<form ...>
...
<div><input type="checkbox" ... />
<label>...</label></div>
...
</form>
div { height: 1.3em; position: relative; }
div input,
div select { position: absolute;
top: 0; left: 7em;
}
84. Forms – basic styling
<form ...>
...
<div class="check"><input type="checkbox" ...
/>
<label>...</label></div>
...
</form>
div { height: 1.3em; position: relative; }
div input,
div select { position: absolute;
top: 0; left: 7em;
}
div.check input { position: relative; left: 0; }
85. Forms – basic styling
<form ...>
<label> ... <input /></label>
<label> ... <input /></label>
<label> ... <select> ... </select> </label>
<label class="check"><input /> ... </label>
<input type="submit" ... />
</form>
label { height: 1.3em; position: relative; }
label input,
label select { position: absolute;
top: 0; left: 7em;
}
label.check input { position: relative;
left: 0;
}
86. Forms – basic required fields
<form ...>
...
<label class="req"> ...<span>(required)</span>
<input /></label>
...
</form>
...
label.req span { position: absolute;
top: 0; left: -999em;
}
label.req { color: #f00; font-weight: bold; }
88. Layout
Look at a micro-layout for general technique:
<div class="example">
<img ... />
<p>Image caption</p>
...
Main body of text
...
</div>
div.example { background-color: #fff9b2;
padding: 20px;
}
89. Layout
div.example { background-color: #fff9b2;
padding: 20px 20px 20px 340px;
position: relative;
}
div.capimage p { font-size: 0.6em;
font-weight: bold;
}
div.capimage { position: absolute;
top: 20px; left: 20px;
}
90. Layout
div.example { background-color: #fff9b2;
padding: 20px 340px 20px 20px;
position: relative;
}
div.capimage p { font-size: 0.6em;
font-weight: bold;
}
div.capimage { position: absolute;
top: 20px; right: 20px;
}