Comp5347 W2 HTML CSS-1
Comp5347 W2 HTML CSS-1
Application Development
Introduction to HTML
and CSS
Dr. Basem Suleiman
School of Computer Science
Content based on Ch2 and Ch3 of Fundamentals of Web Development, Global Edition.
“To publish information for global distribution, one needs a universally understood
language, a kind of publishing mother tongue that all computers may potentially
understand. The publishing language used by the World Wide Web is HTML” –
(from Hyper Text Markup Language)
– W3C stopped work on XHTML 2.0 and adopted the work by WHATWG
and named it HTML5 (2009)
– An HTML element
– Text, other elements, or be empty
– Identified in the HTML document by tags
Trailing Slash
<body> parent
child
<p>
This is some <strong>text</strong>
</p>
<h1>Title goes here</h1>
sibling
<div>descendants
<p>
This is <span>important</span>
</p>
</div>
</body>
<body>
descendants children
<strong> <p>
ancestors
<span>
Correct Nesting
Incorrect Nesting
• The title is typically displayed by the browser in its window and/or tab
1 <!DOCTYPE html>
<title>A Very Small Document</title>
<p>This is a simple document with not much content</p>
1 <!DOCTYPE html>
<html>
2 <head lang="en">
<meta charset="utf-8"> 5
3 <title>Share Your Travels -- New York - Central Park</title>
<link rel="stylesheet" href="css/main.css"> 6
<script src="js/html5shiv.js"></script> 7
</head>
<body>
<h1>Main heading goes here</h1>
4 ...
</body>
</html>
1 <!DOCTYPE html>
<html>
2 <head lang="en">
<meta charset="utf-8"> 5
3 <title>Share Your Travels -- New York - Central Park</title>
<link rel="stylesheet" href="css/main.css"> 6
<script src="js/html5shiv.js"></script> 7
</head>
<body>
<h1>Main heading goes here</h1>
4 ...
</body>
</html>
1 <!DOCTYPE html>
<html>
2 <head lang="en">
<meta charset="utf-8"> 5
3 <title>Share Your Travels -- New York - Central Park</title>
<link rel="stylesheet" href="css/main.css"> 6
<script src="js/html5shiv.js"></script> 7
</head>
<body>
<h1>Main heading goes here</h1>
4 ...
</body>
</html>
1 <!DOCTYPE html>
<html>
2 <head lang="en">
<meta charset="utf-8"> 5
3 <title>Share Your Travels -- New York - Central Park</title>
<link rel="stylesheet" href="css/main.css"> 6
<script src="js/html5shiv.js"></script> 7
</head>
<body>
<h1>Main heading goes here</h1>
4 ...
</body>
</html>
1 <!DOCTYPE html>
<html>
2 <head lang="en">
<meta charset="utf-8"> 5
3 <title>Share Your Travels -- New York - Central Park</title>
<link rel="stylesheet" href="css/main.css"> 6
<script src="js/html5shiv.js"></script> 7
</head>
<body>
<h1>Main heading goes here</h1>
4 ...
</body>
</html>
<h3>Reviews</h3>
6 <div> 7
<p>By Ricardo on <time>September 15, 2012</time></p>
<p>Easy on the HDR buddy.</p>
</div>
<div>
<p>By Susan on <time>October 1, 2012</time></p>
<p>I love Central Park.</p>
</div>
8
Label (image)
Specifies the URL of the image to display Text in title attribute will be displayed in a popup
(note: uses standard relative referencing) tool tip when user moves mouse over image.
Text in alt attribute provides a brief Specifies the width and height of
description of image’s content for users who image in pixels.
are unable to see it.
Entity Description
Nonbreakable space
< <
> >
© ©
™ ™
<p>This photo was taken on October 22, 2011 with a Canon EOS 30D camera.</p>
<figure>
<img src="images/central-park.jpg" alt="Central Park" /><br/>
Figure could be <figcaption>Conservatory Pond in Central Park</figcaption>
moved to a </figure>
different <p>
location in
It was a wonderfully beautiful autumn Sunday, with strong sunlight and
document
expressive clouds. I was very fortunate that my one day in New York was
…
blessed with such weather!
But it has to
</p>
exist in the
document
(i.e., the
figure isn’t
optional)
– Maintainability
– Easy to update and change (structure only!)
– Performance/speed
– Faster to download and quicker to author
– Accessibility
– Sight disabilities experience the web using voice reading software
– Semantic web makes it easier to read
– HTML
– Syntax
– Structure
– Quick Tour
– Semantic Markups
– CSS
– Syntax and Location
– Selector
– The box model
– Text Styling
<head>
<meta charset="utf-8">
<title>Share Your Travels -- New York - Central Park</title>
<style>
h1 { font-size: 24pt; }
h2 {
font-size: 18pt;
font-weight: bold;
}
</style>
</head>
<body>
...
<head>
<meta charset="utf-8">
<title>Share Your Travels -- New York - Central
Park</title>
<link rel="stylesheet" href="styles.css" />
</head>
– In Chrome, check
https://chromium.googlesource.com/chromium/blink/+/master/Source/core/css/html.css
– Inheritance
– Certain properties defined for the <body> element will be inherited by all elements
embedded in it
– Inheritable: font, color, list and text properties
– Not Inheritable: layout, sizing, border, background and spacing properties
– Specificity
– Style rules with more specific selector will override rules with more general selector
• E.g. If both <body> and <p> elements define a font rule, the text inside the <p>
element will use the font defined in the <p> element
– Location
– The latest (closest) rule wins If inheritance and specificity cannot determine style
precedence
• E.g. inline rule is closer to that element than the rules in an external file
declaration block
selector
em { color: red; }
property value
p {
margin: 5px 0 10px 0;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
}
<div>
<p class="first">By Susan on <time>October 1, 2012</time></p>
<p>I love Central Park.</p>
</div>
<hr/>
</body>
The background color or image fills an element out to its border (if
it has one that is).
background-image: url(../images/backgrounds/body-background-tile.gif);
background-repeat: repeat;
p {
border: solid 1pt red;
margin: 30px;
padding: 0;
}
p {
border: solid 1pt red;
margin: 30px;
padding: 30px;
}
50px
div {
2 90px border: dotted 1pt green;
padding: 0;
50px margin: 90px 20px;
}
50px 5
p {
50px border: solid 1pt red;
padding: 0;
3 90px margin: 50px 20px;
}
If overlapping margins did not collapse, then margin space for would be 180p (90pixels for the bottom
margin of the first <div> + 90 pixels for the top margin of the second <div>), while the margins and
for would be 100px.
– On screen-based media
– Pixel has been a relatively stable measure
– Device Pixel vs. CSS pixel
CSS3 supports a new relative measure, the rem (for root em unit).
This unit is always relative to the size of the root element (i.e., the <html> element).
WYSIWYG Editors
Code Editors
Week 3:
More HTML and JavaScript
Client-side Scripting