Web Programming (2)
Web Programming (2)
• <h1> defines the most important heading. <h6> defines the least
important heading:
• HTML paragraphs are defined with <p> tag.
HTML Links, images
• HTML links are defined with <a> tag (anchor tag)
• <a href="https://www.google.com"> Google </a>
Syntax:
<tagname style="property:value;">
The property is a CSS property. The value is a CSS value.
Properties
• background-color
• color (text color)
• font-family ( like verdana etc.. )
• font-size ( text size like 300%)
• text-align (horizontal text alignment like center)
HTML text formatting
• <b> - Bold text (physical tag)
• <strong> - Important text (logical tag)
• <i> - Italic text
• <em> - Emphasized text (logical tag, italicized)
• <mark> - Marked text (highlighted)
• <small> - Smaller text (compare it with <big>)
• <del> - Deleted text (usually strukthrough)
• <ins> - Inserted text (usually underlined)
• <sub> - Subscript text
• <sup> - Superscript text
• <u>, <strike>
HTML Quotation and citation
elements.
• <blockquote> Defines a section that is quoted from another source
• <q> defines a short inline quotation.
• <abbr> defines an abbreviation or an acronym
<abbr title = “ longer form”>shorter form </abbr>
• <address> tag defines the contact information for the author/owner
of a document or an article (email address, phone number, URL, social
media handle, physical address, etc.).
• <cite> defines the title of a creative work (for work title) (eg. A book,
a poem, a song, a movie, a painting, a sculpture, etc.)
HTML Comments
• <!-- Write your comments here -->
• are notes in the HTML code that explain the important features of the
code.
HTML Colors
• HTML colors are specified with predefined color names (Orange,
gray, violet, blue, brown, green, gold, pink, cyan, purple, white,
yellow), or
with RGB(example: blue is rgb(0,0,255)), pink is rgb(255,192,203)),
HEX (#0000FF for blue, #FFC0CB for pink) ,
HSL(hue-a degree on the color wheel from 0 to 360. 0 is red, 120 is
green etc., saturation (0% means a shade of gray, 100% is the full
color), lightness (0% is black, and 100% is white): Example:
hsl(0,100%,50%) ),
RGBA, or HSLA values (a is alpha which is opacity – level of
transparent. 0.0 is fully transparent and 1.0 is not transparent at all
(hsla (0, 100%, 50%, 0.5)
HTML Lists
• To specify lists of information and each item starts with <li> tag
• 3 types:
• Ordered List <ol> or numbered list
• Unordered List <ul> or bulleted list
• Description List <dl> or definition list
• Example:
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Lists – un-numbered
• Unnumbered Lists
Lists:with different pointer types:
<UL>type="square">
<UL
<LI> oranges
apples </LI>
</LI>
<LI> peaches
bananas </LI>
<LI> grapes
grapefruit
</LI>
</LI>
</UL>
type="square"
type="disc"
type="circle"
Lists - numbered
• Numbered
Unnumbered
Lists:
Lists:
<OL>
<UL>
<LI> oranges
apples </LI>
</LI>
<LI> peaches
bananas </LI>
<LI> grapes
grapefruit
</LI>
</LI>
</UL>
</OL>
Lists - numbered
• Numbered Lists with
that starts
different
withordering:
4:
<OL type="a">
start="4">
<LI> oranges </LI>
<LI> peaches </LI>
<LI> grapes </LI>
</OL>
type="a": a, b, c
type="A": A, B, C
type="i": i, ii, iii
type="I": I, II, III
Description list <dl>
• The <dl> tag defines the description list, the <dt> tag defines the term
(name), and the <dd> tag describes each term:
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
Lists
TIPS
Use the start and type attributes to customize your lists.
It is possible to make lists of lists, which is helpful for
creating some items, such as outlines.
MARQUEE TAG
• This tag is used text horizontally across the screen.it is mainly used to
deliver a specfic message to the visitor or to scroll Ads on a page.
• Example: <marquee> hello world></marquee>
Attributes of marquee tag
• A favicon (favorite icon) is a tiny icon included along with a website, which is
displayed in places like the browser's address bar, page tabs and bookmarks
menu.
• A favicon image is displayed to the left of the page title in the browser tab, like
this:
• Syntax
• <link rel = “icon” type = “image/icon type” href =
“image path”>
HTML CSS
• Used to format the layout of a webpage
• With CSS, you can control the color, font, the size of text, the spacing
between elements, how elements are positioned and laid out, what
background images or background colors are to be used, different
displays for different devices and screen sizes, and much more
CSS contd.
• CSS is a stylesheet language used to describe the
presentation of a document written in HTML
• CSS describes how HTML elements should be displayed.
• CSS is the code that styles web content.
• Like HTML, CSS is not a programming language. It's not
a markup language either. CSS is a style sheet
language.
Ways to insert CSS
• Inline - by using the style attribute inside HTML elements
• Internal - by using a <style> element in the <head> section
• External - by using a <link> element to link to an external CSS file
CSS Syntax
Example: p as a selector to style
<p>
p {
color: red;
text-align: center;
}
In this example all <p> elements will be center-aligned, with a red text
color:
Inline CSS
• Used to apply a unique style to a single HTML element.
• Uses the style attribute of an HTML element.
• The following example sets the text color of the <h1> element to blue,
and the text color of the <p> element to red:
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
Example: set the text color of ALL the <h1> elements (on that
page) to maroon. In addition, the page will be displayed with a
“linen" background color:
• <head>
<style>
body {
background-color: linen;
}
h1 {
color: maroon;
margin-left: 40px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
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.
• An external style sheet can be written in any text editor, and must be
saved with a .css extension.
• The external .css file should not contain any HTML tags.
Example: style.css
• body {
background-color: powderblue;
}
h1 {
color: blue;
}
p {
color: red;
}
p {
border: 2px solid powderblue;
margin: 50px;
}
CSS comments
• CSS comments are generally written to explain your code. It is very
helpful for the users who reads your code so that they can easily
understand the code.
• Comments are ignored by browsers.
• Comments are single or multiple lines statement and written
within /*............*/ .
CSS Colors (rgb, rgba, hex,
• rgb(red, green, blue)
• Example: <h2 style="background-color:rgb(255, 0, 0);">rgb
values example</h2>
• rgba(red, green, blue, alpha)
• Example: <h2 style="background-color:rgba(255, 99, 71,
0.8);">Alpha transparent from 0 to 1 example</h2>
• #rrggbb
• Example: <h2 style="background-color:#3cb371;">Hex Values
of color example</h2>
• hsl(hue, saturation, lightness)
• Example: <h2 style="background-color:hsl(0, 100%,
50%);">Hue Saturatioin and Lightness example</h2>
HTML Table
• To arrange data into rows and columns (tabular form)
• <table> <tr><td><th> elements are used
• <table> defines a table
• <tr> defines a table row
• <td> defines a cell in a table
• <th> defines a header cell in a table
• <caption> defines a table caption
• <colgroup> specifies a group of one or more columns in a table for formatting
• <col> specifies column properties for each column within a <colgroup> element
• <thead> groups the header content in a table
• <tbody> groups the body content in a table
• <tfoot> groups the footer content in a table.
Example:
• <table>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Vodaphone</td>
<td>Nick Read</td>
<td>United Kingdom</td>
</tr>
<tr>
<td>Ethio Tel</td>
<td>Frehiwot Tamiru</td>
<td>Ethiopia</td>
</tr>
</table>
Table border
• To add a border, use the CSS border property on table, th, and td elements:
table, th, td {
border: 1px solid black;
}
To avoid double borders around table and cells:
border-collapse: collapse
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
Styling table borders, header and
cells
table, th, td {
border: 1px solid white;
border-collapse: collapse;
}
th, td {
background-color: #96D4D4;
}
To get round cornered borders:
border-radius: 10px;
To change the appearance of the border:
border-style: dotted;
th, td {
border-style: dashed;
border-color: #96D4D4;
}
Table Sizes: use width, height
<table style="width:100%">
<tr>
<th style="width:70%">Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
• By default, browsers use the standard box model. If you want to turn
on the alternative model for an element, you do so by setting box-
sizing: border-box on it. By doing this, you are telling the browser to
use the border box, as shown above, as your defined area.
box {
box-sizing: border-box;
}
div {
width: 300px;
border: 15px solid green;
padding: 50px;
margin: 20px;
}
<div>
Lorem ipsum...
</div>
Width and height of an element
• When you set the width and height properties of an element with
CSs, you just set the width and heigh of the content area.
• To calculate the full size of an element, you must add padding,
borders and margins.
<p>
This is an inline span <span style="border: 1px solid
black">Hello World</span> element inside a paragraph.
</p>
Inline elements example
• <a><abbr><acronym><b>
• <big>
• <br>
• <cite>
• <em><i>
• <img>
• <q><small>
• <span>
• <strong>
• <sub><sup>
The <span> element
• An inline container used to mark up a part of a text, or a part of a
document.
• The <span> element has no required attributes, but style, class and id
are common.
• When used together with CSS, the <span> element can be used to
style parts of the text:
<p>My mother has <span style="color:blue;font-
weight:bold">blue</span> eyes and my father
has <span style="color:darkolivegreen;font-
weight:bold">dark green</span> eyes.</p>
This tag should be used to wrap any
specific word that you want to highlight in
your webpage.
<p>
My mother
has <span style="color:blue">blue</span> eyes.
</p>
• <body>
• <h2>Span Example</h2>
• <p><span style="background-color:lightgreen">
GeeksforGeeks</span> is A Computer Science Portal where
you can<span style="color:blue;"> Publish</span> your own <span
style="background-color:lightblue;">articles</span> and share your
knowledge with the world!!
• </p>
• </body>
HTML Class & ID
• The HTML class attribute is used to specify a class for an HTML
element.
• Multiple HTML elements can share the same class.
dot className
<p class = “para1”> paragraph 1 to be styled .</p>
<p class = “para2”>paragraph 2 is to be styled .</p>
In CSS Stylesheet:
#id_name {
// CSS Property
}
CSS Selectors
• A CSS selector selects/finds the HTML element(s) you want to style.
• Basic CSS selectors:
• Element selector (element)
• Id selector (#id)
• Class selector (.class)
• Universal selector (*)
• Grouping selector
CSS element selector
• The element selector selects HTML elements based on the element
name.
p {
text-align: center;
color: red;
}
Here, all <p> elements on the page will be center-aligned, with a red
text color
CSS id selector
• The id selector uses the id attribute of an HTML element to select a specific
element.
• The id of an element is unique within a page, so the id selector is used to
select one unique element!
• To select an element with a specific id, write a hash (#) character, followed by
the id of the element.
#para1 {
text-align: center;
color: red;
}
The CSS rule above will be applied to the HTML
element with id="para1"
CSS class selector
.city {
text-align: center;
color: red;
}
//for specific HTML element
p.city {
text-align: center;
color: red;
}
For more than one class
<head>
<style>
p.para1 { text-align: center; color: red; }
p.para2 { font-size: 300%; }
</style>
</head>
<body>
<p class=“para1">This paragraph will be red and center-
aligned.</p>
<p class=“para1 para2">This paragraph will be red,
center-aligned, and in a large font-size.</p>
</body>
CSS Universal Selector
• The universal selector (*) selects all HTML elements on the page.
* {
text-align: center;
color: blue;
}
• The CSS rule above will affect every HTML element on the page
The CSS grouping Selector
h1, h2, p {
text-align: center;
color: red;
}
Same as:
h1 {
text-align: center;
color: red;
}
h2 {
text-align: center;
color: red;
}
p {
text-align: center;
color: red;
HTML Head element
• The HTML <head> element is a container for the following elements:
<title>, <style>, <meta>, <link>, <script>, and <base>.
• <title> ---title of the document, shown in the title bar or page tab
• <style> --to define style information
• <link> -- to link external documents (like external style sheets)
• <meta> --to specify character set, page description, keywords, author of
the document, and viewport settings
• <script> -- for JavaScript (client side script)
• <base> --specifies the base URL and/or the target for all relative URLs in
a page (i.e., default URL and/or target for pages)
<meta> tag common attributes
• charset specifies the character encoding for the HTML document
• name specifies name for the metadata (e.g., author, keywords,
description, application-name…)
• content specifies the values associated with name
<meta>
<head>
<meta charset="UTF-8">
<meta name="description" content="Free Web
tutorials">
<meta name="keywords" content="HTML, CSS,
JavaScript">
<meta name="author" content="John Doe">
<meta name="viewport" content="width=device-
width, initial-scale=1.0">
</head>
<meta charset="utf-8">
• This element specifies the document's character encoding — the
character set that the document is permitted to use. utf-8 is a
universal character set that includes pretty much any character from
any human language. This means that your web page will be able to
handle displaying any language; it's therefore a good idea to set this
on every web page you create! For example, your page could handle
English and Amharic just fine
HTML Layout Elements
• Header
• Footer
• Section
• Article
• Aside
• Nav
• Details
• summary
HTML <article> <header> tag
• The <article> tag specifies independent, self-contained content.
• An article should make sense on its own and it should be possible to
distribute it independently from the rest of the site.
• Potential sources for the <article> element:
• Forum post
• Blog post
• News story
• A news paper article
• A user-submitted comment
<header> <aside>
• <aside> tag defines some content aside from the content it’s placed
in.
• The content should be indirectly related to the surrounding content
• Content in aside is a stand-alone, non-essential part of the web page,
and if you delete it, the main content will not be affected.
• Endnotes, comments, lists of terms, reference information, a
collection of links, pull-quotes, etc. are examples of information that
can be within the <aside> element.
<body>
<p>I have watched Game of Thrones last year.</p>
<aside style = “float: right; width: 30%; padding-left: 15px;>
<p> Game of Thrones is, by the way, an American fantasy drama
television series created by David, adapted from A Song of Ice and Fire
fantasy novels. </p>
</aside>
</body>
<header>
• Defines a header for a document or a section.
• Represents a container for introductory content or a set of
navigational links
• A <header> element typically contains:
• One or more heading elements (h1 –h6)
• Logo or icon
• Authorship info
HTML Semantic Elements
• Semantic elements = elements with a meaning
• A semantic element clearly describes its meaning to both the browser
and the developer
• Examples:
non-semantic: <div>, <span> -- tells nothing about its content
Semantic: <section>, <table>, <article>, <aside>, <nav>, <header>,
<time>, <footer>, <main>, <summary>, <form>, etc.
HTML <section> element
• Defines a section in a document
• A section is a thematic grouping of content, typically with a heading
• Examples of where a <section> element can be used:
• Chapters
• Introduction
• News items
• Contact information
Try this one
<h1> Homepage </h1>
<section>
<h2>About Us</h2>
<p>Befo Sew Foundation is established by Daniel Kibret to honor, recognize and
award kind and benevolent persons in Ethiopia.
</p>
</section>
<section>
<h1> contact us </h1>
<address>
Email: someone@gmail.com <br>
Location: Debre Markos
</address>
</section>
Two sections in a document
example
<section>
<h1>Bego Sew Foundation </h1>
<p>Befo Sew Foundation is established by Daniel Kibret to honor,
recognize and award kind and benevolent persons in Ethiopia.
</p>
</section>
<section>
<h1> ESS </h1>
<p> ESS is an Ethiopian space science society established in 2004, with 47 founding
members.
</P>
</section>
How to use section in HTML
• Wrap the related elements you want to group together in section
tags. Most sections should contain a heading
Nesting <article> in <section> and
vice versa
• You will find HTML pages with <section> elements containing
<article> elements, and <article> elements containing <section>
elements.
HTML <footer> element
• Defines a footer for a document or section
• A <footer> element typically contains:
• Authorship info
• Copyright info
• Contact info
• Sitemap
• Back to top links
• Related docs
NB. You can have several <footer> elements in one document
Tip: Contact info inside <footer> should go inside an <address> tag
HTML <nav> element
• Defines a set of navigational links (menus, tables of contents, indexes,
etc.)
<nav>
<a href="/html/">HTML</a> |
<a href="/css/">CSS</a> |
<a href="/js/">JavaScript</a> |
<a href="/python/">jQuery</a>
</nav>\
Output:
HTML | CSS | JavaScript | jQuery
HTML <figure> and <figcaption>
elements
• The <figure> tag specifies self-contained content like illustrations,
diagrams, phots, code listings, tables, charts, etc.
• The <figcaption> tag defines a caption for a <figure> element.
• The <img> element defines the actual image/illustration.
<figure>
<img src=“MLK.jpg" style="width:100%">
<figcaption>Fig.1 – Martin
Luther</figcaption>
</figure>
<figure> tag
• figure tag contains mostly two tags:
• img src
• figcaption
HTML Layout Techniques
Layout contd.
• Four different techniques to create multicolumn layouts
• CSS Framework
• CSS float property
• CSS flexbox
• CSS grid
CSS Frameworks (read about them)
• Comprises several CSS stylesheets ready for use by web developers
and designers
• Examples
• Bootstrap (an initiative by Twitter)
• Foundation
• Bulma
CSS float Layout
• Use the float and clear properties
• The CSS float property specifies how an element should float
• The CSs clear property specifies what elements can float beside the
cleared element and on which side
• float: left/right/none/inherit (values)
float property values
• left/right the element floats to the left/right of its container
• none the element does not float (will be displayed just where it
occurs in the next). This is default
• inherit the element inherits the float value of its parent.
In its simplest use, the float property can be used to wrap text around
images.
example
<p>
Hello In the Other side.
</p>
<img src="MLK.jpg" alt="" width="20%"
height="50%“ style = “float: right”>
div2 {
clear: left;
}
This example clears the float to the left. Here, it means
that the <div2> element is pushed below the left floated
<div1> element:
Clear:both
Try this one
<div style="border: 2px solid red; overflow: auto;" >
<img src="MLK.jpg" alt="" width="100"
height="100" style="float: right;">
• <p>Lorem ipsum dolor sit amet consectetur
adipisicing elit. Quis dolorem cum totam, magni odio
autem blanditiis, beatae molestias ipsa aliquam
nihil? Architecto, itaque consectetur ducimus natus
cumque odit reprehenderit doloremque.
</p>
</div>
CSS Text
• color
• background-color
• text-align (to set the horizontal alignment of text)
• Left/right/center/justify
• Justify each line is stretched so that every line has equal width and the left and right margins are
straight
• Direction rtl or ltr or inherit
• Unicode-bidi embed, normal,bidi-override
• Text-decoratioin overline, line-through, underline
• Text-transform uppercase, lowercase, capitalize
• Letter-spacing space between characters in a text (eg. 3px)
• Word-spacing:10px
Video and Audio in HTML
<video src=“tilahun.mp4" width="320" height="240
" controls>
Your browser does not support the video tag.
</video>
Use Multiple Source formats to
improve compatibility
<video width="320" height="240" controls>
<source src=“tilahun.mp4" type="video/mp4">
<source src=“teddy.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
The <source> element allows you to specify alternative
video files which the browser may choose from. The
browser will use the first recognized format.
• Fallback content: The text between the <video> and </video> tags
will only be displayed in browsers that do not support the <video>
element
• Controls/autoplay/muted
• Controlsadds video controls, like play, pause and volume
• Autoplay to start a video automatically
• Autoplay muted to start automatically but no sound
Audio
<audio controls>
<source src=“Tsedi.ogg" type="audio/ogg">
<source src=“Zeritu.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
Automatically but no sound
• <audio controls autoplay muted>
<source src=“teddy.ogg" type="audio/ogg">
<source src=“tilahun.mp3" type="audio/mpeg">
Your browser does not support the audio
element.
</audio>
CSS Combinator
CSS Combinators
• Four different combinators in CSS
• Descendant selector (space)
• Child selector (>)
• Adjacent sibling selector (+)
• General sibling selector (~)
Descendant Selector
• The descendant selector is a way to select elements that are located
somewhere underneath other elements, according to the tree
structure of the webpage.
• This selector is actually multiple selectors combined together, but
separated by a space.
• The first selector is the "ancestor", the element(s) that must be
located higher in the tree, and the second selector is the
"descendant", the element(s) that must be located somewhere
underneath the ancestor in the tree.
Descendant selector (space)
div p {
background-color: yellow;
}
The first selector above is a descendant selector. It will select any list
items that are anywhere underneath an unordered list in the markup
structure. The list item could be buried three levels deep within other
nested lists, and this selector will still match it.
&entity_name; OR
&#entity_number;
<label for="first-name">Name:</label>
<input type="text" id="first-name" name="first-
name" value="your name here..">
Text fields <text>
<form>
<label for="fname">First Name: </label>
<input type="text" id="fname“> <br><br>
<input type="submit" value="submit">
</form>
The for attribute of the <label> tag should be equal to
the id attribute of the <input> element to bind them
together.
Radio Buttons (<radio>)
<form>
<input type="radio" name="gender" id="male" value="Male">
<label for="male">Male</label>