Ref: Google Code University - HTML, CSS, and JavaScript from the Ground Up on Youtube
Separation of Content, Presentation, and Behavior Code
Graceful Degradation / Progressive Enhancement
Don't Ignore Errors
Naming Convention for URLs (SEO technique)
Keep it Short
Using Keywords in Foldernames and Filenames
Avoid Querystrings (e.g., ?page=11 is BAD)
Basically, make it readable for both Humans and Bots
Check List: https://ist.mit.edu/sites/default/files/migration/usability/selected.guidelines.pdf
<!-- Some Comments Here -->
<tagName attributeName="attriValue">Some Content</tagName>
<!-- Closing a content-less tag -->
<tagName attrName="attrVal" />
<!-- Some BAD Examples that look the same: -->
<h1 align="center">Hello World!</h1>
<center><font size="7">Hello World!</font></center>
<!-- Good Example:
- style can be reused and put in a separate file -->
<style>.centered{text-align:center}</style>
<h1 class="centered">Hello World!</h1>
<!DOCTYPE html><!-- this is to tell what HTML version -->
<html>
<head> <!-- head tag contains some meta-info tags -->
<meta charset="utf-8" /> <!-- to specify the doc encodings -->
<title>IERG4210 HTML5 Hello World!</title>
</head>
<body> <!-- body tag contains some content -->
<h1>Hello World!</h1>
</body>
</html>
Ref: https://developer.mozilla.org/en-US/docs/Sections_and_Outlines_of_an_HTML5_document
<h1>Header 1</h1>
<h2>Header 2</h2>
<h3>Header 3</h3>
...
<h6>Header 6</h6>
Press [Enter] above (L.H.S.) to see the updates on the right
<p>Paragraph 1</p>
<p>Unordered List</p>
<ul>
<li>item 1</li>
<li>item 2</li>
</ul>
<p>Ordered List</p>
<ol>
<li>item 1</li>
<li>item 2</li>
</ol>
<p>Below are more semantic!</p>
<strong>Strong</strong>
<em>Emphasis</em>
<p>Below are more stylistic!</p>
<b>bold</b>
<i>italic</i>
<h1>Absolute URLs:</h1>
<a href="http://www.google.com/">HTTP Google</a>
<a href="https://www.google.com/">HTTPS Google</a>
<!--Follows the Current Protocol:-->
<a href="//www.google.com/">??? Google</a>
incl/
cuhk-logo.png
test2.html
test1.html
<h1>In test1.html:</h1>
<a href="incl/test2.html">test2.html</a>
<h1>In incl/test2.html:</h1>
<a href="../test1.html">test1.html</a>
<a href="/~ierg4130/">IERG4130</a>
Given the same directory structure and HTML code:
incl/
cuhk-logo.png
test2.html
test1.html
<h1>Img in Absolute URL:</h1>
<img src="http://www.iso.cuhk.edu.hk/english/images/resource/cuhk-emblem/hor_4c.jpg" />
<h1>Img in Relative URL:</h1>
<img src="../incl/cuhk-logo.png" />
<img src="/~ierg4210/incl/cuhk-logo.png" />
<table>
<tr><!--table row-->
<th>First Name</th>
<th>Last Name</th>
</tr>
<tr>
<td>Scarlett</td>
<td>Johansson</td>
</tr>
<tr>
<td>Elizabeth</td>
<td>Olsen</td>
</tr>
</table>
<td> is a simple data cell, while <th> stands for a header cell
Drawback: Table often does not fit well in small screens
<table>
<tr><th>First Name</th>
<th>Last Name</th></tr>
<!--Merging the cell in next row-->
<tr><td rowspan="2">Scarlet</td>
<td>Johansson</td></tr>
<tr><td>Witch</td></tr>
<!--Merging the cell in next column-->
<tr><td colspan="2">
You Took Everything From Me!!!</td></tr>
</table>
<!-- Method 1: link to an extern CSS file -->
<link href="styles.css" rel="stylesheet" type="text/css" />
<!-- Method 2: Embedded CSS inside a specific HTML page-->
<!-- CDATA: Character Data; #F00: RGB color coding -->
<style>//<![CDATA[
p{color:#F00}
//]]></style>
<!-- Method 3: attach CSS to certain HTML tag directly -->
<p>inline <span style="color:#00FF00">CSS</span></p>
selector1{
propertyName1:propertyVal1;
propertyName2:propertyVal2
}
<style>
*,body{color:#00F}
p{color:#F00}
p.highlight{background:#FF0}
p.highlight2{background:#CCC}
p.highlight2 * {color:#000}
#uniqueId1{font-size:30px;color:#00FF00}
</style>
<h3>inherited the color!</h3>
<p>Oh</p>
<p class="highlight">My</p>
<p class="highlight highlight2">God<em>!<em></p>
<p id="uniqueId1">overridden the
color</p>
<style>
p{color:#F00}
p.highlight{background:#FF0}
#uniq1,#uniq2{color:#00FF00}
div p.highlight{background:#CCC}
</style>
<p class="highlight">Hello World!</p>
<p class="highlight" id="uniq1">Yo!</p>
<div id="uniq2">
<p class="highlight">Hello!</p>
</div>
Example: CSS-enhanced Horizontal Item List / Navigation Menu
<style>
.menu{padding:0;list-style-type:square}
.menu li{font-size:19px;display:inline}
#xx {font-size:4px}
#yy {font-size:38px} </style>
<nav><!-- <nav> is a semantic tag! -->
<ul class="menu">
<li id="xx"><a id="yy" href="#">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</nav>
<ul>
<li><a href="#a">Home</a></li>
<li><a href="#b">About Us</a></li>
<li><a href="#c">Contact Us</a></li>
</ul>
<style>
.menu a:link{color:#00F}
.menu a:hover{font-weight:bold}
.menu a:visited{color:#F00}
</style>
<nav>
<ul class="menu">
<li><a href="#a">Home</a></li>
<li><a href="#b">About Us</a></li>
<li><a href="#c">Contact Us</a></li>
</ul>
</nav>
<a href="#">Remains unmodified (the default)</a>
<style>
nav ul{display:none}
nav:hover ul{display:block}
</style>
<nav>
<h3>MENU</h3>
<ul>
<li><a href="#a">Home</a></li>
<li><a href="#b">About Us</a></li>
<li><a href="#c">Contact Us</a></li>
</ul>
</nav>
Some Content
<style>
ul li:nth-child(even){color:#CCC}
ul li:nth-child(2n){background:#333}
ul li:nth-child(2n+1){background:#EEE}
</style>
<ul>
<li>Home</li>
<li>About Us</li>
<li>Products</li>
<li>Contact Us</li>
</ul>
<style>
.para1{color:#0F0;line-height:150%}
.para2{color:#F00;font-size:150%}
</style>
<p class="para1">Have I not commanded you? Be strong and courageous. Do not be afraid; do not be discouraged, for the LORD your God will be with you wherever you go.</p>
<p class="para2">Have I not commanded you? Be strong and courageous. Do not be afraid; do not be discouraged, for the LORD your God will be with you wherever you go.</p>
<style>
.title{text-align:center}
.para{text-align:justify;color:#F00}
.right{text-align:right}
</style>
<h1 class="title">Joshua 1:9</h1>
<p class="para">Have I not commanded you? Be strong and courageous. Do not be afraid; do not be discouraged, for the LORD your God will be with you wherever you go.</p>
<p class="right">Copyright. NIV.</p>
<style>
nav ul{
display:none;position:absolute;margin:-20px
}
nav:hover ul{display:block}
</style>
<nav>
<h3>MENU</h3>
<ul>
<li><a href="#a">Home</a></li>
<li><a href="#b">About Us</a></li>
<li><a href="#c">Contact Us</a></li>
</ul>
</nav><p>Some Content</p>
The Box Model as displayed in Firebug for the element ul
- position layer: top, right, bottom, left
- margin layer: margin-top, margin-right, margin-bottom, margin-left
- border layer: border-top, border-right, border-bottom, border-left
- padding layer: padding-top, padding-right, padding-bottom, padding-left
- Or equiv., margin:1px 2px 3px 4px; for top, right, bottom and left direction
<style>
p.wide{margin:10px;padding:5px}
p.border,p.wide{border:3px solid #CCC}
p.LRonly{border-top:0;border-bottom:0}
p.lifted{margin-top:-50px}
</style>
<p>Content 1</p>
<p class="wide">Content 2</p>
<p class="border">Content 3</p>
<p class="border LRonly">Content 4</p>
<p class="lifted">Content 5</p>
<!-- Try resizing the width to 180px -->
<style>
ul.table{width:240px;height:240px;
margin:0;padding:0;list-style:none;
overflow:auto}
ul.table li{width:70px;height:90px;
float:left;border:1px solid #CCC}
.clear{clear:both}
</style>
<ul class="table">
<li><img src="../fig/lec2-souvenir.jpg" />Product 1</li>
<li>Product 2</li><li>Product 3</li>
<li>Product 4</li><li>Product 5</li>
<li>Product 6</li><li>Product 7</li>
</ul>
<p class="clear">Total: 7</p>