Module 9 - HTML and CSS
Module 9 - HTML and CSS
Module 9:
HTML
IT 111: Introduction to Computing
3
Hypertext Markup Language
▸ HTML
-one of the three main components of modern web pages,
along with Cascading Style Sheets(CSS) and JavaScript.
-indicates to the browser what elements should be
included in the webpage
-is a language for specifying how text and graphics appear
on a web page
“
Sample HTML Document
▸ HTML
▸ is a textual language that includes special markup tags
such as:
<title> Bob’s Diner </title>
▸ The <title>..</title> tag specifies a title for the web page.
▸ HTML code is stored in a simple text file that has either a
.htm or a .html filename extension (e.g., restaurant.html)
6
HTML Basic
▸ <!DOCTYPE> Declaration
▸ represents the document type, and helps
▸ browsers to display web pages correctly.
▸ It must only appear once, at the top of
▸ the page (before any HTML tags).
▸ The <!DOCTYPE> declaration is not case
sensitive.
7
HTML Basic
▸ HTML Title
▸ A title is usually displayed on the top bar of a web browser’s
window when you visit a web site
▸ The title will now be displayed in the main web browser window,
just on the top bar
▸ <title> is the start tag
▸ </title> is the end tag
8
HTML Basic
▸ HTML Headings
▸ HTML headings are titles or subtitles that you want to display
on a webpage.
▸ HTML allows you to create sections in a document using
headings, there are six levels of headings
▸ HTML headings are defined with the <h1> to <h6> tags.
▸ <h1> defines the most important heading. <h6> defines the
least important heading.
9
HTML Basic
▸ HTML Headings
10
HTML Basic
▸ HTML Paragraphs
▸ The HTML <p> element defines a
paragraph.
▸ A paragraph always starts on a new
line, and browsers automatically add
some white space (a margin) before
and after a paragraph.
11
HTML Attributes
HTML attributes provide additional information about HTML elements.
▸ The <a> tag defines a hyperlink. The href attribute specifies the URL of the page
the link goes to:
13
▸ The <img> tag is used to embed an image in an HTML page. The src attribute specifies
the path to the image to be displayed:
▸ The required alt attribute for the <img> tag specifies an alternate text for an
image, if the image for some reason cannot be displayed. This can be due to slow
connection, or an error in the src attribute, or if the user uses a screen reader.
15
HTML Comments
HTML comments are not displayed in the browser, but they can help
document your HTML source code.
You can also hide more than one line, everything between the <!-- and the -->
will be hidden from the display.
21
HTML Colors
Color Names
In HTML, a color can be specified by using a color name:
HTML Colors
Background Color
You can set the background color for HTML elements:
Text Color
23
HTML Colors
Border Color
24
HTML Colors
RGB Color Values
In HTML, a color can be specified as an RGB value, using this formula:
● Each parameter (red, green, and blue) defines the intensity of the color with a value
between 0 and 255.
● This means that there are 256 x 256 x 256 = 16777216 possible colors!
25
HTML Links
HTML Links - Hyperlinks
● HTML links are hyperlinks.
● You can click on a link and jump to another document.
● When you move the mouse over a link, the mouse arrow will turn into a little hand.
● The most important attribute of the <a> element is the href attribute,
which indicates the link's destination.
26
HTML Links
HTML Links - Use an Image as a Link
Button as a Link
27
HTML Links
Link Titles
The title attribute specifies extra information about an element. The information is
most often shown as a tooltip text when the mouse moves over the element.
28
To create a bookmark - first create the bookmark, then add a link to it.
31
HTML Images
The <img> tag has two required attributes:
HTML Images
Background Image on a HTML element
To add a background image on an HTML element, use the HTML style attribute and the CSS
background-image property:
33
HTML Images
Background Cover
● If you want the background image to cover the entire
element, you can set the background-size property
to cover.
● Also, to make sure the entire element is always
covered, set the background-attachment property to
fixed:
● This way, the background image will cover the entire
element, with no stretching (the image will keep its
original proportions):
34
HTML Tables
HTML tables allow web developers to arrange data into rows and columns.
35
HTML Tables
HTML tables allow web developers to arrange
data into rows and columns.
36
HTML Lists
HTML Lists
HTML Lists
HTML Lists
42
CSS
IT 111: Introduction to Computing
46
CSS
● describes how HTML elements are to be displayed on screen, paper,
or in other media
● saves a lot of work. It can control the layout of multiple web pages all
at once
CSS
CSS is used to define styles for your web pages, including the design,
layout and variations in display for different devices and screen sizes.
48
CSS Syntax
The selector points to the HTML element you want to style.
Each declaration includes a CSS property name and a value, separated by a colon.
Multiple CSS declarations are separated with semicolons, and declaration blocks
are surrounded by curly braces.
49
● External CSS
● Internal CSS
● Inline CSS
53
● External CSS
● With an external style sheet, you can change the look of an entire website by
changing just one file!
● Each HTML page must include a reference to the external style sheet file inside the
<link> element, inside the head section.
54
● Internal CSS
● An internal style sheet may be used if one single HTML page has a unique
style.
● The internal style is defined inside the <style> element, inside the head
section.
56
CSS Comments
● Comments are used to explain the code, and may help when you edit the source code at a
later date.
● Comments are ignored by browsers.
● A CSS comment is placed inside the <style> element, and starts with /* and ends with */:
59
CSS Colors
CSS Background Color
CSS Backgrounds
The background-color property
specifies the background color of an
CSS background-color element.
61
CSS Backgrounds
Other Elements
You can set the background color for any HTML elements:
62
CSS Backgrounds
Opacity / Transparency
The opacity property specifies the opacity/transparency of an element. It can take a value from 0.0 -
1.0. The lower value, the more transparent:
63
CSS Backgrounds
CSS background-image
● The background-image property specifies an image to use as the background of
an element.
● By default, the image is repeated so it covers the entire element.
64
CSS Borders
The border-style property specifies what kind of border to display.
CSS Margins
The CSS margin properties are used to create space around
elements, outside of any defined borders.
● margin-top
● margin-right
● margin-bottom
● margin-left
66
CSS Margins
67
CSS Padding
● The CSS padding properties are used to generate space around an element's
content, inside of any defined borders.
● With CSS, you have full control over the padding. There are properties for
setting the padding for each side of an element (top, right, bottom, and left).
● padding-top
● padding-right
● padding-bottom
● padding-left
68
The height and width properties do not include padding, borders, or margins. It sets the height/width of the
area inside the padding, border, and margin of the element.
69
● auto - This is default. The browser calculates the height and width
● length - Defines the height/width in px, cm etc.
● % - Defines the height/width in percent of the containing block
● initial - Sets the height/width to its default value
● inherit - The height/width will be inherited from its parent value
70
CSS Fonts
Generic Font Families
In CSS there are five generic font families:
1. Serif fonts have a small stroke at the edges of each letter. They create a
sense of formality and elegance.
2. Sans-serif fonts have clean lines (no small strokes attached). They create a
modern and minimalistic look.
3. Monospace fonts - here all the letters have the same fixed width. They
create a mechanical look.
4. Cursive fonts imitate human handwriting.
5. Fantasy fonts are decorative/playful fonts.
72
CSS Fonts
73
CSS Lists
Different List Item Markers
● The list-style-type property specifies the type of
list item marker.
● The following example shows some of the available
list item markers:
74
CSS Tables
● Table Borders
● To specify table borders in CSS, use the border
property.
● The example below specifies a black border for
<table>, <th>, and <td> elements:
75
CSS Tables
76
Thank you!