server services,
e.g., MySQL/MariaDB

|

dynamic content/presentation:
PHP

|
webserver:
e.g., Apache
HTML, CSS, JavaScript

/\
|
\/
client:
web-browser
dynamic content/presentation:
JavaScript

|
client:
web-browser
content:
HTML
presentation:
CSS

css-1. defining css

Cascading Style Sheet (CSS) describes how to display HTML elements. Different CSS for the same HTML file can result in very different layout of the webpage.

Try the demo One HTML Page - Multiple styles at https://www.w3schools.com/css/css_intro.asp

The CSS definition may be:
(1) external CSS, using an external style sheet for many web pages, e.g., in a web site ;
(2) internal CSS, using <style> element in the <head> section for a single web page;
(3) inline, using <style> attribute in the HTML element and is for that element only.

Reference: CSS How To at https://www.w3schools.com/css/css_howto.asp

Return to css menu

css-1.1 Syntax

Syntax with single property:
property:value;>
Examples:
<body style="background-color:yellow;">

Syntax with multiple properties:
<property1:value1; property2:value2;
Example:
<h1 style="color: yellow; justify-content: center;">

Syntax for property to take multiple values:
property:value1 value2 value3;
Example:
<div style="border:solid green 5px;">

Syntax for property to choose one value from multiple choices in order of preferences:
property:value1,value2,value3;
Example:
<p style="font-family: verdana, geneva, sans-serif;">

Syntax with function values:
property:function(value1,value2,value3);
color:rgb(0,255,255);

Return to css menu

css-1.2 Inline css

Syntax:

<tag_name style="declaration_1;...; "> html element content</tag_name>

Inline example:
<p style="color:green;font-size:160%;font-family:verdana;">Green and enlarged heading</p>
<h4 style="color:green;font-size:160%;font-family:verdana;">Green and enlarged paragraph</h4>
<div style="color:green;font-family:courier;">Green text</div>

displaying (without the red box):

Green and enlarged heading

Green and enlarged paragraph

Green text

Return to css menu

css-1.3 Internal css

Syntax:

<head>
...
<style>
selector {declaration_1;declaration_2;...;}
</style>
...
</head>

selector is a tag_name to point to the HTML element to style.

Each declaration is property:value

Syntax to define style for multiple elements in head section:

<style>
selector_01,selector_02,... {declaration_01;declaration_02;...;}
selector_11 {declaration_11;declaration_12;...;}
selector_21,selector_02,selector_11... {declaration_21;...;}
</style>

Internal CSS example:
<style>
p, h4, div {
  color:green;
}
p, h4 {
  font-size:160%;
  font-family:verdana;
}
div {
  font-family:courier;
}
</style>

Reference: CSS syntax at https://www.w3schools.com/css/css_syntax.asp

Return to css menu

1.4 External css

Syntax: The head section of the html file contains

<link rel="stylesheet" href="filename.css">

The css file contains

selector {property_1:value_1;property_2:value_2;...;}

Syntax to define style for multiple elements in css file:

selector_01,selector_02,... {property_01:value_01;property_02:_02;...;}
selector_11 {property_11:value_11;property_12:value_12;...;}
selector_21,selector_02,selector_11... {property_21:value_21;...;}

External CSS example:
A file called: mystyle.css contains
p, h4, div {
  color:green;
}
p, h4 {
  font-size:160%;
  font-family:verdana;
}
div {
  font-family:courier;
}
The link element in the head of the html file points to the css file.

<!DOCTYPE html>
<html>
  <head>
<link rel="stylesheet" href="mystyle.css">
  </head>
  <body>
    <h4>Green and enlarged heading</h4>
    <p>Green and enlarged paragraph</p>
    <div>Green text</div>
  </body>
</html>

Reference: CSS syntax at https://www.w3schools.com/css/css_syntax.asp

Return to css menu

1.5 validation

CSS validation service is available at https://jigsaw.w3.org/css-validator/

Return to css menu

1.6 exercise

  1. Create a webpage with customized styles for headings, paragraphs, div, etc. using in-line css.
  2. Create a webpage but using internal css, such that the webpage is identical to above webpage uisng in-line css
  3. Create a webpage but using external css, such that the webpage is identical to above webpage uisng in-line css

Return to css menu

css-2. Selector

HTML element

Use element name to select an HTML element

Example to select all the paragraph elements in the HTML file:

p { color:blue }

Multiple HTML elements

Use element names separated by , to select mulitple HTML elements

Example to select all the h1, h2 elements in the HTML file:

h1, h2 { text-align:center }

All HTML elements

Use * to select all HTML elements

Example to select all the elements in the HTML file:

* { color:blue }

HTML element with class-name

Use .class-name to select the HTML elements with class=class-name

Example to select the paragraph elements with class="right" in HTML file:

p.right { text-algin:right }

Example to select all elements with class="center" in HTML file:

.right { text-algin:center }
SELECTOR
PROPERTY
element
property
element_name { property : value ; }
p { color : blue ; }
multiple elements
property
element_name_1 , element_name_2 { property : value ; }
h1 , h2 { text-algin : center ; }
all elements
property
* { color : blue ; }
element with class
property
element_name . class { property : value ; }
p . right { text-algin : right ; }
all elements with class
property

. class { property : value ; }

. right { text-algin : center ; }

Reference: CSS Selectors at hhttps://www.w3schools.com/css/css_selectors.asp

Return to css menu

css-2.1 class vs id

SELECTOR
PROPERTY
all elements with class
property

. class_name { property : value ; }

. right { text-algin : center ; }
the element with unique id
property

# id_name { property : value ; }

# right-007 { font-size : 0.8em ; }

Class name in HTML

Syntax of class attribute in html file:
<tag_name class="class_name">

Multiple lass names in HTML

Syntax of multiple class attributes in html file:
<tag_name class="class_name1 class_name2 ...">

Example of class
<html>
  <head>
    <style>
    p.right {
    text-align:right;
    font-size:0.8em;
    }
    </style>
  </head>
  <body>
    <p class="right">This paragraph is aligned to right</p>
    <p>This is a regular paragraph </p>
  </body>
</html>

displaying (without the red box):

This paragraph is aligned to right

This is a regular paragraph

Example of class
<html>
  <head>
    <style>
    .right {
    text-align:right;
    font-size:0.8em;
    }
    </style>
  </head>
  <body>
    <h3 class="right">This heading is aligned to right</h3>
    <p>This is a regular paragraph </p>
  </body>
</html>

displaying (without the red box):

This heading is aligned to right

This is a regular paragraph

id must be unique within the same html file, and is therefore more often used to bookmark an element to enable linking to the element. Still CSS may be defined for the bookmarked element.

Example of defining CSS for an id-bookmarked element
<html>
  <head>
    <style>
    #right-007 {
    text-align:right;
    font-size:0.8em;
    }
    </style>
  </head>
  <body>
    <h3 id="right-007">This is the only heading in this web page with the id "right-007"</h3>
    <p>This is a regular paragraph </p>
  </body>
</html>

Return to css menu

css-2.2 Combinators

SELECTOR:
PROPERTY
descendant(s)
property
element
descendant_element { property : value ; }
div.right
p { color : blue ; }

child/children
property
element > child_element { property : value ; }
section > p { color : blue ; }

subsequent sibling elements
property
1st element ~ sibling element after 1st { property : value ; }
h1 ~ p { color : blue ; }

Use space to select descendant HTML elements

Example to select all the paragraph elements (including child of child, etc.) in the div container in the HTML file:

div p { color:blue }

which applies to every p element in the div element.

div.class_name p { color:blue }

which applies to every p element in those div element of class class_name.

Use > to select child HTML elements

Example to select only the paragraph elements directly in the section container (paragraph in a div container which is in turn under a section container is excluded) in HTML file:

section > p { color:blue }

Reference: Many more possible CSS Combinators are at https://www.w3schools.com/css/css_combinators.asp

Return to css menu

css-2.3 pseudo-class

pseudo-class
property
selector : pseudo-class { property : value ; }
every link
property
a : link { color : blue ; }
visited link
property
a : visited { color : purple ; }
mouse over link
property
a : hover { color : red ; }
selected link
property
a : active { font-size : 150% ; }

Example
In CSS:

	/* every link */
h6 > a:link    {color:blue; background-color:yellow; text-decoration:none;}
	/* visited link */
h6 > a:visited {color:green;}
	/* mouse over the link */
h6 > a:hover {font-size:larger; color:red;}
	/* selected link */
h6 > a:active {font-size:larger; color:red;}
	

In HTML:
<h6><a href="#css-00">Return to css menu</a></h6>

Resulting link is inside the following red box:

Return to css menu

a:hover MUST come after a:link and a:visited .
a:active MUST come after a:hover in the CSS definition.

Reference: Many more possible CSS pseudo-classes are at https://www.w3schools.com/css/css_pseudo_classes.asp

Return to css menu

css-2.4 pseudo-element

::after /* after element
::before /* before element
::first-letter /* first letter of element
::first-line /* first line of element
::selection /* the part of element selected by user

pseudo-element { property : value ; }
first letter
property
p :: first-letter { font-size : xx-large ; }
first line
property
p :: first-line { font-variant : small-caps ; }
insert before element
property
p :: before { content : ../images/myball.gif ; }
insert after element
property
h2 :: after { content : ../images/logo-cihe.png ; }
selection
property
p :: selection { background-color : yellow ; }

Return to css menu

css-2.4.1 ::first-letter, ::first-line

::first-letter ::first-line

/* first letter applicable only to block element */
p::first-letter {font-size:200%}
/* select first line*/
div::first-line {color:purple}

Applicable properties for first-line are:

font properties
color properties
background properties
word-spacing
letter-spacing
text-decoration
vertical-align
text-transform
line-height
clear

Applicable properties for first-letter are:

font properties
color properties 
background properties
margin properties
padding properties
border properties
text-decoration
vertical-align (only if "float" is "none")
text-transform
line-height
float
clear

Example
In CSS:
div.css-020401::first-letter {font-size:xx-large; }
div.css-020401::first-line {color:green; }

In HTML:
<div class="css-020401">The first letter of these text and the first line are standing out compared with the remaining text. The text after the first line does not stand out any more.</div>

will display (without the red box):

The first letter of these text and the first line are standing out compared with the remaining text. The text after the first line does not stand out any more.

Return to css menu

css-2.4.2 ::before, ::after

::before ::after

/* insert an icon before h1 */
h1::before {content:url(picture.jpg);}
/* append to a paragraph */
p::after {content:url(picture.jpg);}

Example
(You may click following images/myball.gif to open the image, then save the image to a folder ../images to try the following yourself)
In CSS:
h3.css-020402::before {content:url(../images/myball.gif);}
p.css-020402::after {content:url(../images/myball.gif);}
img.css-020402 {float:left;}
div.css-020402-clear::after {content:"";clear:both;display:table;}

In HTML
<h3 class="css-020402">Section One</h3>
<img class="css-020402" src="../images/logo-caritas.jpg" style="height:180px;">
<p class="css-020402">First paragraph</p>
<p class="css-020402">Second paragraph</p>
<h3 class="css-020402">Section Two</h3>
<h3 class="css-020402">Section Three</h3>

will display (without the red box):

Section One

First paragraph

Second paragraph

Section Two

Section Three

In HTML: Contents of Section One nested in element to clear
<h3 class="css-020402">Section One</h3>
<div class="css-020402-clear">
<img class="css-020402" src="../images/logo-caritas.jpg" style="height:180px;">
<p class="css-020402">First paragraph</p>
<p class="css-020402">Second paragraph</p>
</div>
<h3 class="css-020402">Section Two</h3>
<h3 class="css-020402">Section Three</h3>

will display (without the red box):

Section One: contents nested in element to clear

First paragraph

Second paragraph

Section Two

Section Three

Reference Clear Floats at
https://www.w3schools.com/css/tryit.asp?filename=trycss_layout_clearfix2

Return to css menu

css-2.4.3 ::selection

::selection

/* highlight the portion of an element selected by a user */
::selection {background:yellow;}

Applicable properties for first-letter are:

color
background
cursor
outline

Example
In CSS:
p.css-020403::selection {color:red; background:yellow;}

In HTML:
<p class="css-020403">The appearance of text in this paragraph will change when the text is selected by user.</p>

will display (without the red box):

The appearance of text in this paragraph will change when the text is selected by user.

Reference: Many more possible CSS pseudo-elements are at https://www.w3schools.com/css/css_pseudo_elements.asp

Return to css menu

css-2.5 attribute selector


attribute selector { property : value ; }

[ attribute ] { property : value ; }
a [ target ] { background-color : yellow ; }

attribute value selector { property : value ; }

[ attribute = "value" ] { property : value ; }
a [ target = "_blank" ] { background-color : yellow ; }


contains

[ attribute ~= "whole word" ] { property : value ; }
a [ title ~= "peace" ] { border : 5px solid yellow ; }


contains

[ attribute *= "value" ] { property : value ; }
a [ title *= "pe" ] { background : yellow ; }


starts with

[ attribute |= "whole word" ] { property : value ; }
a [ class |= "css" ] { background : yellow ; }


begins with

[ attribute ^= "value" ] { property : value ; }
a [ class ^= "css" ] { background : yellow ; }


ends with

[ attribute $= "value" ] { property : value ; }
a [ class $= "test" ] { background : yellow ; }

Reference: Read CSS attribute selector at https://www.w3schools.com/css/css_attribute_selectors.asp

Return to css menu

2.6 exercise

Using internal css with "class" attribute in html, create a webpage with multiple paragraph elements such that certain paragraphs are aligned to the right, but the remaining paragraphes remain aligned to the left.

Using external css with "class" attribute in html, create a webpage with multiple paragraph elements such that certain paragraphs are aligned to the right, but the remaining paragraphes remain aligned to the left.

Return to css menu

css-3. css box model

border surrounds the element plus the padding
padding is space surrounding the element inside the border
margin is space outside the border.
element has size expressed in width and height

Example, in the css file or within style element in head section:
div {
background-color:yellow;
border:5px solid green;
padding:10px;
margin:50px;
}

Modern Society will find no solution to the ecological problem unless it takes a serious look at its lifestyles. (Pope John Paul II)

Read and practice CSS box model at
https://www.w3schools.com/css/css_boxmodel.asp

Return to css menu

css-3.1 border

The border property is a shorthand for
border-style(required)
border-width
border-color properties

Syntax:
border-style:dotted|dashed|solid|double|groove|ridge|inset|outset|none|hidden;
border-width:value;
border-color:value;

Example:
The border may be
<span style="border-style:dotted;border-color:#00ee90;">dotted</span>,
<span style="border-style:dashed;border-color:purple;">dashed</span>,
<span style="border-style:solid;border-width:10px;">solid</span>,
<span style="border-style:double;border-width:10px;">double</span>,
<span style="border-style:hidden;border-width:10px;">hidden</span>,
<span style="border:solid yellow 5px;">solid yellow 5px</span>,
<span style="border:inset green 5px;">inset green 5px</span>,
<span style="border:outset 5px brown;">outset 5px brown</span>,
<span style="border-style:none;">none</span>,
..., etc.

The border may be dotted, dashed, solid, double, hidden, solid yellow 5px, inset green 5px, outset 5px brown, none, ..., etc.

Read and practice CSS Borders at
https://www.w3schools.com/css/css_border.asp

Return to css menu

css-3.1.1 border-radius

border-radius rounds the corner.

Example:
The borders are rounded by <span style="border:double green 5px;border-radius:3px">3px</span>,
<span style="border:solid green 5px;border-radius:5px;">solid green 5px</span>,
<span style="border:solid green 5px;border-radius:10px;">10px</span>,
respectively.

The borders are rounded by 3px, solid green 5px, 10px, respectively.

Read and practice CSS Borders at
https://www.w3schools.com/css/css_border.asp

Return to css menu

css-3.2 padding

The padding property is a shorthand for
padding-top
padding-right
padding-bottom
padding-left
properties

Syntax (4 values):
tag {
padding:top right bottom left;
}

Syntax (3 values):
tag {
padding:top right=left bottom;
}

Syntax (2 values):
tag {
padding:top=bottom right=left;
}

Syntax (single value):
tag {
padding:top=bottom=right=left;
}

Example

border:dotted green 5px;
padding:10px;

Read and practice CSS Padding at
https://www.w3schools.com/css/css_padding.asp

Return to css menu

css-3.3 box-sizing

Syntax:
box-sizing:content-box|border-box|initial|inherit;

box-sizing:content-box (default) width/length = content

box-sizing:border-box width/length = content + padding + border-width

Example

width:300px;
border:solid yellow 20px;background-color:pink; box-sizing:content-box;
width:300px;
border:solid pink 10px; box-sizing:border-box;
width:300px;
border:inset brown 10px;padding:20px;
width:300px;
border:inset brown 10px;padding:20px;
width:300px;
border:dashed purple 2px;
box-sizing:content-box;
width:300px;
border:dashed purple 2px;
box-sizing:border-box;
width:300px;
border:solid green 10px;
padding:20px;
box-sizing:border-box;
width:300px;
border:solid yellow 30px;
padding:10px;
box-sizing:border-box;
border-radius:60px;

Reference: box-sizing at hhttps://www.w3schools.com/cssref/css3_pr_box-sizing.asp

Return to css menu

css-3.4 margin

The margin property is a shorthand for
margin-top
margin-right
margin-bottom
margin-left
properties

Syntax (4 values):
tag {
margin:top right bottom left;
}

Syntax (3 values):
tag {
margin:top right=left bottom;
}

Syntax (2 values):
tag {
margin:top=bottom right=left;
}

Syntax (single value):
tag {
margin:top=bottom=right=left;
}

The margin:auto property horizontally centers the element within its container.

Example

width:300px;
border:double orange 10px;
margin:20px;
width:300px;
border:inset brown 10px;
padding:20px;
margin:20px;
width:300px;
border:dashed purple 2px;
margin:20px;
width:300px;
border:groove green 10px;
padding:20px;
box-sizing:border-box;
margin:20px;
width:300px;
border:ridge green 10px;
padding:20px;
box-sizing:border-box;
margin:auto;

Refer to: display at https://www.w3schools.com/css/css_float.asp

Read and practice CSS Margins at
https://www.w3schools.com/css/css_margin.asp

Return to css menu

css-3.5 outline

The outline property is a shorthand for
outline-width
outline-style(required)
outline-color properties

Example

width:300px;
border:solid yellow 20px;background-color:pink; box-sizing:content-box;
width:300px;
border:solid yellow 20px;outline:dashed green 5px;background-color:pink; box-sizing:content-box;
width:300px;
border:solid yellow 20px;margin:20px;background-color:pink; box-sizing:content-box;
width:300px;
border:solid yellow 20px;outline:dashed green 5px;margin:20px;background-color:pink; box-sizing:content-box;
width:300px;
border:solid pink 10px; box-sizing:border-box;
https://www.w3schools.com/css/css_outline_shorthand.asp

Reference: outline at https://www.w3schools.com/css/css_outline_shorthand.asp

Return to css menu

css-3.6 exercise

Create a webpage using internal css with a block of text showing its border similar to that in Section 3 above.
Add more in-line text with a variety of borders: solid, dotted, dashed, double, hidden, groove, inset, outset.

Create a webpage using external css with a block of text showing its border similar to that in Section 3 above.
Add more in-line text with a variety of borders: solid, dotted, dashed, double, hidden, groove, inset, outset.

In a webpage, add a block of text with round radius border and defining box-sizing.
add another block of text, also with identical round radius border, but without defining box-sizing.
Choose your border parameters such that the difference between the border with and without box-sizing can be obviously seen. Explain the difference.

Return to css menu

css-4. Layout

Return to css menu

css-4.1 display and visibility

Syntax:
display:value;

Commonly used display property values:

display:inline; does not start new line

display:block; starts new line and takes full width of container

display:none; does not leave blanked gap

display:inline-block; respects padding, margin

There are many other values, such as display:table; to display like a table element, which are defined at:

Reference: display property at hhttps://www.w3schools.com/cssref/pr_class_display.asp

Syntax:
visibility: visible|hidden|collapse|initial|inherit;

visibility:hidden; blanks the contents leaving gap

visibility:visible; is default

visibility:collapse; only for table row, row groups, column, column groups

Reference: visibility property at hhttps://www.w3schools.com/cssref/pr_class_visibility.asp

Example of changing span display from the default of inline to block:

display:inline;
The fear of making permanent commitments can change the mutual love of husband and wife into two loves of self - two loves existing side by side, until they end in separation. (Pope John Paul II)

display:block;
The fear of making permanent commitments can change the mutual love of husband and wife into two loves of self - two loves existing side by side, until they end in separation. (Pope John Paul II)

display:none;
The fear of making permanent commitments can change the mutual love of husband and wife into two loves of self - two loves existing side by side, until they end in separation. (Pope John Paul II)

visibility:hidden;
The fear of making permanent commitments can change the mutual love of husband and wife into two loves of self - two loves existing side by side, until they end in separation. (Pope John Paul II)

Reference: display, visibility at https://www.w3schools.com/css/css_display_visibility.asp

Example of inline vs inline-block:

display:inline;
The fear of making permanent commitments can change the mutual love of husband and wife into two loves of self - two loves existing side by side, until they end in separation. (Pope John Paul II)

display:inline; padding:10px; margin:20px;
The fear of making permanent commitments can change the mutual love of husband and wife into two loves of self - two loves existing side by side, until they end in separation. (Pope John Paul II)

display:inline-block; padding:10px; margin:20px;
The fear of making permanent commitments can change the mutual love of husband and wife into two loves of self - two loves existing side by side, until they end in separation. (Pope John Paul II)

Reference: display:inline-block at https://www.w3schools.com/css/css_inline-block.asp

Return to css menu

css-4.2 position

Syntax:
position:static|relative|fixed|absolute|sticky;

position:static; no change to normal position
position:relative; relative to normal position
position:fixed; relative to viewport (of the web browser); scrolling does not move it.
position:absolute; relative to the first relatively positioned parent element.
position:sticky; switches between relative and fixed depending on whether a given offset position is or is not met in the viewport.

Example

position:absolute;
width:200px;
height:200px;
right:20px;
relative to nearest positioned ancestor
position:static;
width:300px;
height:200px;
color:blue;
border:dotted yellow 30px;

(no change to normal position)
position:relative;
width:300px;
height:200px;
color:red;
border:solid black 30px;
left:50px;top:100px;

(relative to normal position)
position:static;
width:300px;
height:200px;
color:blue;
border:dotted yellow 30px;

(no change to normal position)
position:relative;
width:300px;
height:200px;
color:red;
border:solid black 30px;
left:50px;top:-100px;
z-index:-1;

(relative to normal position)

Refer to: position at https://www.w3schools.com/css/css_positioning.asp

Return to css menu

css-4.3 width, height

Syntax:
width:value
height:value
max-width:value
max-height:value
min-width:value
min-height:value

value may be:
auto to let browser calculate
length and unit with unit in px, em, cm, etc.
length and % of the containing block
initial to set to the default value
inherit from its parent value

Reference: width, height at https://www.w3schools.com/css/css_dimension.asp

Example with max-width

testing with max-width:500px; and margin:auto;

Reference: max-width at https://www.w3schools.com/css/css_max-width.asp

Return to css menu

css-4.4 float, clear

float

Syntax:
float:left|right|none|inherit;

float:left|right; floats content to the left/right of its container
float:none; is default to display where it occurs
float:inherit; inherits the float value from its parent

Example

Both image and text are in div element with css float:none; border:dashed yellow 10px; color:green; width:300px;
This image has css float:left; Both image and text are in div element with css float:left; border:dashed pink 10px; width:300px;
These text are in div element with css border:solid brown 5px; color:green; width:400px;

clear

Syntax:
clear:left|right|both|none|inherit;

float:left|right|both; not allow floating elements on left/right/both sides
float:none; is default to allow floating elements
float:inherit; inherits the clear value from its parent

Example

This image has css float:left; Both image and text are in div element with css float:left; border:dashed yellow 10px; color:green; width:300px; height:150px;
These text are in div element with css border:solid brown 5px; clear:left; width:400px; height:220px;

Reference: float and clear at https://www.w3schools.com/css/css_float.asp

Return to css menu

css-4.5 overflow

Syntax:
overflow:visible|hidden|scroll|auto;

overflow:hidden; clips the remaining content
overflow:visible; show the overflowed content outside the container
float:scroll; clips but provides scroll bar to view the overflowed content
overflow:auto; provides scroll only when needed

Example

This image has css float:left; Both image and text are in div element with css overflow:visible; border:dashed yellow 10px; color:green; width:300px; height:90px;

Next heading

This image has css float:left; Both image and text are in div element with css overflow:hidden; border:dashed pink 10px; width:300px; height:90px;

Next heading

This image has css float:left; Both image and text are in div element with css overflow:scroll; border:dashed yellow 10px; color:green; width:300px; height:90px;
This image has css float:left; Both image and text are in div element with css overflow:auto; border:dashed pink 10px; width:300px; height:90px;
This image has css float:left; Both image and text are in div element with css overflow:auto; border:dashed yellow 10px; color:green; width:300px; height:200px;
This image has css float:left; Both image and text are in div element with css overflow:auto; border:dashed pink 10px; width:300px;

Reference: overflow at https://www.w3schools.com/css/css_overflow.asp

Return to css menu

css-4.6 align

css-4.6.1 Center horizontally:

text-align:center; centers text-only element horizontally

margin:auto; centers block element if its width < width of its container (need display:block; if element is not block by default)

display:block;margin:auto; centers an img element

text-align:center; border:dashed 5px yellow; color:green;
width:50%; margin:auto; border:dashed 5px pink;

Return to css menu

css-4.6.2 Center vertically:

padding:top=bottom right=left; to set padding-top = padding-bottom

line-height to set equal vertical spacing between text lines

height to set height of container

set height = line-height to center a single-line text inside the height of the container

padding:50px 0; text-align:center; color:green; border:dashed 5px yellow;
line-height:100px; height:100px; text-align:center; color:red; border:dashed 5px pink;
height:100px; text-align:center; color:green; border:dashed 5px yellow;
line-height:100px; text-align:center; color:red; border:dashed 5px pink;
width:50%; text-align:center; margin:auto; color:green; border:dashed 5px yellow;

position:absolute; to move one corner inward
transform:translate to move to center

text element with css: position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); background-color:pink; inside container with css: position:relative; height:300px; border:dashed 5px yellow;

text element with css: margin:50px auto; width:80%; border:dashed 5px pink;

Reference: align at https://www.w3schools.com/css/css_align.asp

Reference: Centering in CSS: A Complete Guide at https://css-tricks.com/centering-css-complete-guide/

Return to css menu

css-4.6.3 Center and align blocks

images: centered aligned to bottom

css class: text-align:center; margin:auto;

text: centered

css class: text-align:center; margin:auto;
Centered text

inline-blocks of unspecified height: centered and aligned to the bottom

css class: text-align:center; margin:auto;
css class:

position:relative; display:inline-block; width:200px; border:6px dashed yellow; this block is long
css class:

position:relative; display:inline-block; width:200px; border:6px dashed yellow; this block is longer than the long block
css class:

position:relative; display:inline-block; width:200px; border:6px dashed yellow; this block is longest compared with all the other blocks inside the green class
css class:

position:relative; display:inline-block; width:200px; border:6px dashed yellow;

inline-blocks of specified heights: with same contents and relative position are aligned to top

css class: text-align:center; margin:auto;
css class:

position:relative; display:inline-block; width:200px; height:120px; border:6px dashed yellow;
css class:

position:relative; display:inline-block; width:200px; height:140px; border:6px dashed yellow;
css class:

position:relative; display:inline-block; width:200px; height:160px; border:6px dashed yellow;
css class:

position:relative; display:inline-block; width:200px; height:100px; border:6px dashed yellow;

inline-blocks of specified unequal heights: with different contents and relative position results in unpredictable alignment (align only roughly to bottom here)

css class: text-align:center; margin:auto;
css class:

position:relative; display:inline-block; width:200px; height:120px; border:6px dashed yellow; this block is long
css class:

position:relative; display:inline-block; width:200px; height:140px; border:6px dashed yellow; this block is longer than the long block
css class:

position:relative; display:inline-block; width:200px; height:160px; border:6px dashed yellow; this block is longest compared with all the other blocks inside the green class
css class:

position:relative; display:inline-block; width:200px; height:100px; border:6px dashed yellow;

inline-blocks of specified equal heights: with different contents and relative position results in unpredictable alignment

css class: text-align:center; margin:auto;
css class:

position:relative; display:inline-block; width:200px; height:220px; border:6px dashed yellow; this block is long
css class:

position:relative; display:inline-block; width:200px; height:220px; border:6px dashed yellow; this block is longer than the long block
css class:

position:relative; display:inline-block; width:200px; height:220px; border:6px dashed yellow; this block is longest compared with all the other blocks inside the green class
css class:

position:relative; display:inline-block; width:200px; height:220px; border:6px dashed yellow;

cascading absolute position inside relative position inline-blocks to align to top

css class: text-align:center; margin:auto;
inner css class:

position:absolute; width:100%; height:100%; border:5px dashed pink;

outer css class:

position:relative; display:inline-block; width:200px; height:200px; border:6px dashed yellow;
inner css class:

position:absolute; width:100%; height:100%; border:5px dashed pink;

outer css class:

position:relative; display:inline-block; width:200px; height:200px; border:6px dashed yellow; more text than the first
inner css class:

position:absolute; width:100%; height:100%; border:5px dashed pink;

outer css class:

position:relative; display:inline-block; width:200px; height:200px; border:6px dashed yellow; even more text than the first and the second blocks

cascading absolute position inside relative position inline-blocks to align to bottom

css class: text-align:center; margin:auto;
inner top css class:

position:absolute; width:100%; height:100%; border:5px dashed pink;

outer css class:

position:relative; display:inline-block; width:200px; height:400px; border:6px dashed yellow;
inner bottom css class:
position:absolute; width:100%; height:100px; bottom:0; background-color:pink;
inner top css class:

position:absolute; width:100%; height:100%; border:5px dashed pink;

outer css class:

position:relative; display:inline-block; width:200px; height:400px; border:6px dashed yellow; more text than the first
inner bottom css class:
position:absolute; width:100%; height:100px; bottom:0; background-color:pink;
inner top css class:

position:absolute; width:100%; height:100%; border:5px dashed pink;

outer css class:

position:relative; display:inline-block; width:200px; height:400px; border:6px dashed yellow; even more text than the first and the second blocks
inner bottom css class:
position:absolute; width:100%; height:100px; bottom:0; background-color:pink;

Return to css menu

css-4.6.4 Exercise

Add the following at the end of your work:

Pick 2 picture files of different aspect ratio and with native size not wider than 30% of the width of your screen.

Display each of these these 2 pictures vertically aligned to the right but with the same width.

Display each of these these 2 pictures vertically aligned to the center (between left and right) with the same width.

Display each of these these 2 pictures horizontally aligned and with the same height.

Return to css menu

css-4.7 flex-box:

A flexible layout structure consists of a flex container (parent) element which contains flex items (children) elements in an easer design of a flexible (and responsive) layout stucture without the need to use float or position.

The flex structure is direction-agnostic (no presumption of row, column, direction), with the flex container in a single row/column with a flex direction along a main-axis. The flex items are along a cross-axis perpendicular to the main-axis.

See demo to summarize flexbox at https://flexbox.help/

Return to css menu

css-4.8 flex container (display:flex)

A flex div container is defined with a class-name, e.g., flex-container, with the css style property

Syntax:
display:flex; /* to turn the div element to became a flexible box (as parent) */

Properties of the flexible containers are defined in the following sub-sections.

Reference: flex-container at https://www.w3schools.com/css/css3_flexbox_container.asp

Return to css menu

css-4.8.1 flex-flow (flex-direction flex-wrap)

Syntax:
flex-direction:row|row-reverse|column|column-reverse; /* to change the flow direction. default is in a single row when in English */

Syntax:
flex-wrap:wrap|nowrap|wrap-reverse|initial; /* the default is nowrap in a single line; the multiple lines generated with wrap are treated as separate single lines /*

Syntax:
flex-flow:flex-direction value flex-wrap value; /* is shorthand for flex-direction and flex-wrap. */

Example with flex-direction (flow direction)

In css
	.flex-box1 {
	display:flex;
	flex-direction:row-reverse;
	background-color:green;
	}
	.flex-box2 {
	display:flex;
	flex-direction:column-reverse;
	}
	.flex-box1>div, .flex-box2>div {
	background-color:yellow; 
	width:4em; 
	margin:10px;
	}
	
In html
	<div class="flex-box1">
	  <div>first element is here</div>
	  <div>second element</div>
	  <div>third</div>
	<div>
	<div class="flex-box2">
	  <div>PHY</div>
	  <div>LINK</div>
	  <div>IP</div>
	  <div>TCP</div>
	  <div>APP</div>
	<div>
	
first element is here
second element
third
PHY
LINK
IP
TCP
APP

Return to css menu

css-4.8.2 justify-content

Syntax:
justify-content:center|flex-start|flex-end|space-between|space-around|space-evenly|initial; /* aligns the flex items in the flex container along the main-axis at the center, to the start/end of the flex-direction,
space-between: between items but not at start/end (justify to fill up the main-axis dimension of the container),
space-around: equal spaces before and after each item with doubled spaces between items,
space-evenly: equal spaces before and after each item without doubled spaces between items */

Example to justify-content to become right justified for row

In css
	.flex-box1 {
	display:flex;
	justify-content:flex-end; /* right justify for flex-direction:row */
	}
	.flex-box2 {
	display:flex;
	justify-content:space-between; /* fill up row with space between items */
	}
	.flex-box3 {
	display:flex;
	justify-content:space-evenly; /* fill up row with space at ends and between items */
	}
	.flex-box4 {
	display:flex;
	justify-content:space-around; /* fill up row with space at ends and repeated spaces between items */
	}
	.flex-box1>div, .flex-box3>div, {
	border:background-color:yellow; 
	width:8em;
	}
	.flex-box2>div, .flex-box4>div {
	border:background-color:pink; 
	width:8em;
	}
	
In html
	<div class="flex-box1">
	  <div>first</div>
	  <div>second</div>
	  <div>third</div>
	<div>
	<div class="flex-box2">
	  <div>first</div>
	  <div>second</div>
	  <div>third</div>
	<div>
	<div class="flex-box3">
	  <div>first</div>
	  <div>second</div>
	  <div>third</div>
	<div>
	<div class="flex-box4">
	  <div>first</div>
	  <div>second</div>
	  <div>third</div>
	<div>
	
justify-content: end;
second
third
justify-content: space-between;
second
third
justify-content: space-evenly;
second
third
justify-content: space-around;
second
third

Example to center multiple boxes that flows according to width of browser

In css
	.flex-box {
	display:flex;
	flex-wrap:wrap
	justify-content:space-evenly;
	}
	.flex-box > div {
	width:16em;
	border:10px dotted green; 
	margin:1em;
	}
	
In html
	<div class="flex-box">
	  <div>first <br>element <br>is <br>here</div>
	  <div>second<br>element</div>
	  <div>third</div>
	<div>
	
first
element
is
here
second
element
third

Reference: justify-content at https://www.w3schools.com/cssref/css3_pr_justify-content.asp

Return to css menu

css-4.8.3 align-items

Syntax:
align-items:stretch|center|flex-start|flex-end|baseline|initial|inherit; /* aligns the flex items along the cross-axis to fill up, at the center, to the start/end

Example with align-items

In css
	.flex-box1 {
	display:flex;
	justify-content:space-evenly; /* fill up along the main-axis with evenly spaced items */
	align-items:center; /* align flex items along the cross-axis */
	height:6em;
	}
	.flex-box2 {
	display:flex;
	justify-content:space-evenly; /* fill up along the main-axis with evenly spaced items */
	/* is default to align flex items size along the cross-axis to fill up */
	height:6em;
	}
	.flex-box1>div {
	border:background-color:yellow; 
	width:6em;
	}
	.flex-box2>div {
	border:background-color:pink; 
	width:6em;
	}
	
In html
	<div class="flex-box1">
	  <div>first</div>
	  <div>second</div>
	  <div>third</div>
	<div>
	<div class="flex-box2">
	  <div>first</div>
	  <div>second</div>
	  <div>third</div>
	<div>
	
align-items: center;
second
third

default align-items: stretch;
second
third

Reference: align-items at https://www.w3schools.com/cssref/css3_pr_align-items.asp

Return to css menu

css-4.8.4 align-content

Syntax:
align-content:stretch|center|flex-start|flex-end|space-between|space-around|space-evenly|initial; /* aligns the multiple lines of flex items along the cross-axis at the center, to the start/end of the flex-direction,
space-between: between items but not at start/end (justify to fill up entire line),
space-around: equal spaces before and after each item without overlap - doubling between items,
space-evenly: equal spaces before and after each item with overlap between items */

Example with align-content together with flex-wrap:wrap to align mulitple lines

In css
	.flex-box1 {
	display:flex;
	flex-wrap:wrap;
	justify-content:space-evenly; /* fill up along the main-axis with evenly spaced items */
	align-content:space-evenly; /* evenly spaced lines of flex items along the cross-axis */
	height:6em;
	}
	.flex-box2 {
	display:flex;
	flex-wrap:wrap;
	justify-content:space-evenly; /* fill up along the main-axis with evenly spaced items */
	align-content:stretch; /* fill up cross-axis dimension with lines of flex items */
	height:6em;
	}
	.flex-box3 {
	display:flex;
	flex-wrap:wrap;
	justify-content:space-evenly; /* fill up along the main-axis with evenly spaced items */
	align-content:center; /* center the lines of flex items */
	height:6em;
	}
	.flex-box1>div, .flex-box3>div {
	border:background-color:yellow; 
	width:14em;
	}
	.flex-box2>div {
	border:background-color:pink; 
	width:14em;
	}
	
align-content:space-evenly;
12
13
14
15
default align-content:stretch;
12
13
14
15

align-content:center;
12
13
14
15

Reference: align-items at https://www.w3schools.com/cssref/css3_pr_align-content.asp

Return to css menu

css-4.9 flex-item:

The property of flex div child item may be modified individually.

Syntax:
order:number in the modified order; /* to change the order of the items */

Syntax:
flex-basis:number|auto|initial|inherit; /* specifies the initial size */
flex-grow:number|initial|inherit; /* how many times the child item can grow relative to the rest of flexible items if there is room in the parent element; default is 0 */
flex-shrink:number|initial|inherit; /* how many times the child item can shrink relative to the rest of flexible items if there is not enough room in the parent element;default is 0 */
flex:flex-grow flex-shrink flex-basis|auto|initial|inherit; /* shorthand for flex-grow flex-shrink flex-basis */

Syntax:
align-self:auto|stretch|center|flex-start|flex-end|baseline|initial|inherit; /* to override the align-items */

Reference: flex-items at https://www.w3schools.com/css/css3_flexbox_items.asp

Return to css menu

css-4.9.1 flex-basis:

Syntax:
flex-basis:number|auto|initial|inherit; /* specifies the initial size */

Example: flex-basis

In css

	.flex-040901 {
	display:flex;
	height:6em; 
	background-color:green;
	}

	.flex-040901 div {
	flex-basis:200px;
	background-color:yellow; 
	margin:10px;
	}

	.flex-040901 div:nth-of-type(2) {
	flex-basis:100px;
	}
	

In html

	<div class="flex-040901">
	  <div>1</div>
	  <div>2</div>
	  <div>3</div>
	  <div>4</div>
	</div>
	
flex-basis:200px;
flex-basis:100px;
flex-basis:200px;
flex-basis:200px;

Reference: flex-basis at https://www.w3schools.com/cssref/css3_pr_flex-basis.asp

Return to css menu

css-4.9.2 flex-grow

Syntax:
flex-grow:number|initial|inherit; /* how many times the child item can grow relative to the rest of flexible items if there is room in the parent element; default is 0 */

Grow if the parent element has leftover for the flex items to grow

Example: flex-grow

In css

	.flex-box {
	display:flex;
	height:6em; 
	background-color:green;
	}
	.flex-box > div {
	background-color:yellow; 
	margin:10px;
	justify-content:space-between;
	}
        

In html

	<div class="flex-box">
	  <div style="flex-grow:1;></div>
	  <div style="flex-grow:2;"></div>
	  <div style="flex-grow:1;></div>
	  <div style="flex-grow:.5;></div>
	</div>
        

Reference: flex-grow at https://www.w3schools.com/cssref/css3_pr_flex-grow.asp

Return to css menu

css-4.9.3 flex-shrink

Syntax:
flex-shrink:number|initial|inherit; /* how many times the child item can shrink relative to the rest of flexible items if there is not enough room in the parent element;default is 0 */

Shrink flex item if the parent element does not have enough room

Example: flex-shrink

In css

	.flex-box {
	display:flex;
	height:6em; 
	background-color:green;
	flex-basis:10em;
	}
	.flex-box > div {
	background-color:yellow; 
	margin:10px;
	}
        

In html

	<div class="flex-box">
	  <div style="flex-shrink:1;></div>
	  <div style="flex-shrink:2;"></div>
	  <div style="flex-shrink:1;></div>
	  <div style="flex-shrink:1;></div>
	</div>
        

Reduce width of browser to check how 2nd box shrinks

flex-shrink:1;
flex-shrink:2;
flex-shrink:1;
flex-shrink:1;

Reference: flex-shrink at https://www.w3schools.com/cssref/css3_pr_flex-shrink.asp

Return to css menu

css-4.9.4 order

Example: order

In css

	.flex-box {
	display:flex;
	height:6em; 
	background-color:green;
	}
	.flex-box > div {
	flex-basis:10em;
	background-color:yellow; 
	margin:10px;
	}
	

In html

	<div class="flex-box">
	  <div order:2>1</div>
	  <div order:3>2</div>
	  <div order:4>3</div>
	  <div order:1>4</div>
	</div>
	
1
order:2;
flex-basis:10em;
2
order:3;
flex-basis:10em;
3
order:4;
flex-basis:10em;
4
order:1;
flex-basis:10em;

Reference: order at https://www.w3schools.com/cssref/css3_pr_order.asp

Return to css menu

css-4.9.5 align-self

align the selected item inside the flexible container, overriding the flexible container's align-items property

Syntax:
align-self:auto|stretch|center|flex-start|flex-end|baseline|initial|inherit; /* how many times the child item can shrink relative to the rest of flexible items if there is not enough room in the parent element;default is 0 */

Example: self-align

In css

	.flex-box {
	display:flex;
	height:6em; 
	background-color:green;
	}
	.flex-box > div {
	flex-basis:10em;
	background-color:yellow; 
	margin:10px;
	}
	

In html

	<div class="flex-box">
	  <div>1</div>
	  <div style="align-self:flex-start;">2</div>
	  <div style="align-self:center;>3</div>
	  <div>4</div>
	</div>
	
1
2
3
4

Reference: align-self at https://www.w3schools.com/cssref/css3_pr_align-self.asp

Return to css menu

css-4.10 responsive flexbox:

Changes from row to column using @media query

In css:

.flex-container {
	display:flex;
	justify-content:center; 
	flex-wrap:wrap; 
	background-color:#0c3c63;
	line-height:1em;
	position:relative;
}

.flex-container>div {
	margin:0 6px;
    font-size:small; 
    color:white;
	position:relative;
}

.flex-container>div>div {
	background-color:#0c3c63;
	width:10em;
	top:100%;
	left:0px;
	text-align:left;
	position:absolute;
}

.flex-container>div>div {
	display:none; /* Hide the sub menus */
}

.flex-container div:hover > div {
	display:block; /* diplay child of div upon hovering div */
	z-index:10;
}

.flex-container div>a {
	text-decoration:none; /* removes browser default text-decoration */
	display:block; /* whole link area clickable */
    color:white;
}

.flex-container div>a:hover { 
    font-size:medium; 
	color:#6eadbd;
} /* change appearance upon hovering*/


@media only screen and (max-width:600px) {
	.flex-container { flex-direction:row; 
	flex-direction:column;
	justify-content:flex-start; 
	align-items:flex-start; 
	}
    .flex-container>div {
        margin:0px;
		width:100%;
	}
    .flex-container>div>div {
	top:0px;
	left:20%;
	}
}
    

In HTML:

      <div class="flex-container"> 
		<div><a href="#css-01">Define</a>
		  <div>
		    <div><a href="#css-0101">Syntax</a></div>
		    <div><a href="#css-0102">In-line css</a></div>
		  </div>
		</div>
		<div><a href="#css-02">Selector</a></div>
		<div><a href="#css-03">Box</a></div>
		<div><a href="#css-04">Layout</a></div>
		<div><a href="#css-0503">Text</a></div>
		<div><a href="#css-06">Font</a></div>
		<div><a href="#css-07">Images</a></div>
		<div><a href="#css-08">Color</a></div>
		<div><a href="#css-09">Background</a></div>
		<div><a href="#css-10">UI</a></div>
		<div><a href="#css-11">How to</a></div>
		<div><a href="#css-12">framework</a></div>
		<div><a href="#css-13">Project</a></div>
	  </div>
    

Reference: responsibe flexbox at https://www.w3schools.com/css/tryit.asp?filename=trycss3_flexbox_responsive

Return to css menu

css-5.3 word-wrap:

Syntax:
word-wrap:normal|break-word|initial|inherit;
word-wrap:normal;to break word only at allowed break points
word-wrap:break-word;to allow breaking unbreakable word

Reference: word-wrap at https://www.w3schools.com/cssref/css3_pr_word-wrap.asp

Return to css menu

css-5.4 word-break:

Syntax:
word-break:normal|break-all|keep-all|break-word|initial|inherit;
word-break:break-all;to break word at any character to prevent overflow
word-break:break-word;to break word at arbitrary point to prevent overflow
word-break:keep;not to use break-word for Chinese/Japanese/Korean characters (same as normal for non-CJK characters)

Reference: word-break at https://www.w3schools.com/cssref/css3_pr_word-break.asp

Return to css menu

css-5.5 white-space:

Syntax:
white-space:normal|nowrap|pre|pre-line|pre-wrap|initial|inherit;
white-space:normal;to collapse consecutive spaces to a single whitespace and break when necessary
white-space:nowrap;to collapse consecutive spaces to a single whitespace and continues on same line until encountering <br>
white-space:pre;to preserve spaces and wrap only at line break
white-space:pre-line;to collapse consecutive spaces to a single whitespace and wrap when necessary at at line break
white-space:pre-wrap;to preserve spaces and wrap when necessary at at line break

Reference: white-space at https://www.w3schools.com/cssref/cssref/pr_text_white-space.asp

Return to css menu

css-5.6 word-spacing:

Syntax:
word-spacing:normal|length|initial|inherit;
word-spacing:normal;to define the normal word spacing of 0.25em
word-spacing:length;to define the additional (may be negative) word spacing of length

Reference: word-spacing at https://www.w3schools.com/cssref/cssref/pr_text_word-spacing.asp

Return to css menu

css-5.7 writing-mode:

Syntax:
writing-mode:horizontal-tb|vertical-rl|vertical-lr;
writing-mode:horizontal-tb;to let the content to flow horizontally from left to right and vertically from top to bottom
writing-mode:vertical-rl;to let content to flow vertically from top to bottom and horizontally from right to left
writing-mode:vertical-lr;to let content to flow vertically from top to bottom and horizontally from left to right

writing-mode: vertical-rl; height:200px; border:solid yellow 10px; border-radius:50px;
It is not necessary that whilst I live I live happily; but it is necessary that so long as I live I should live honorably. (Immanuel Kant)

Reference: writing-mode at https://www.w3schools.com/cssref/cssref/css3_pr_writing-mode.asp

Return to css menu

css-5.8 Text decoration:

The text-decoration property is a shorthand property for text-decoration-line (required) text-decoration-color text-decoration-style.
Syntax: text-decoration:text-decoration-line text-decoration-color text-decoration-style|initial|inherit;

The text-decoration-line may be: solid|double|dotted|dashed|wavy|initial|inherit;

The text-decoration-style may be: color|initial|inherit;

The text-decoration-style may be: solid|double|dotted|dashed|wavy|initial|inherit;

Example:
<div> Life of a human being begins at the moment of <span style="text-decoration:underline red wavy;"> conception </span> as the individual has a unique DNA which is different from that of its mother or father.</div>
displays (without the red box):

Life of a human being begins at the moment of conception as the individual has a unique DNA which is different from that of its mother or father.

Read and practice text-decoration at:
https://www.w3schools.com/cssref/pr_text_text-decoration.asp

Return to css menu

css-5.9 Text transform:

Syntax: text-transform: none|capitalize|uppercase|lowercase|initial|inherit;

Example:
<p style="text-transform:capitalize;"> HTML tutorial </p>
displays (without the red box):

HTML tutorial

Example:
<p style="text-transform:uppercase;"> HTML tutorial </p>
displays (without the red box):

HTML tutorial

Return to css menu

css-5.10 Text indent:

Syntax: text-indent:length|initial|inherit;

Example:
<p style="text-indent:50px;"> Life of a human being begins at the moment of conception as the individual has a unique DNA which is different from that of its mother or father. </p>
displays (without the red box):

Life of a human being begins at the moment of conception as the individual has a unique DNA which is different from that of its mother or father.

Return to css menu

css-5.11 Text shadow:

Syntax: text-shadow:h-shadow v-shadow blur-radius color |none|initial|inherit;

Example:
<h2 style="text-shadow:1px 1px 2px #FF0000;"> Dignity of the human person </h2>
displays (without the red box):

Dignity of the human person

Example:
<h2 style="text-shadow:0 0 3px #FF0000, 0 0 5px #0000FF;"> red and blue neon glow shadow</h2>
displays (without the red box):

red and blue neon glow shadow

Example:
<h2 style="color:white; text-shadow:1px 0 #FF0000, -1px 0 #FF0000, 0 1px #FF0000, 0 -1px #FF0000;"> border around text</h2>
displays (without the red box):

border around text

Multiple shadows: comma-separated list of shadows

Read and practice Text show effect at:
https://www.w3schools.com/css/css3_shadows.asp

Return to css menu

css-5.12 link:

selector of link state in following order:
a:link /*a link
a:visited /* a visited link
a:hover/* when moused over / touched
a:active/* the moment link is clicked

Example with
css:
h6 > a:link { text-decoration: none; background-color: yellow;}
h6 > a:visited { color: green; }
h6 > a:hover { font-size: larger; color: brown; }
h6 > a:active { font-size: larger; color: red }

html:
<h6><a href="#css-00">Return to css menu</a></h6>

Return to css menu

Reference: CSS links at https://www.w3schools.com/css/css_link.asp

Return to css menu

css-6. Font

font is shorthand for font-style,
font-variant,
font-weight,
font-size/line-height is required (use default if missing),
font-family is required (use default if missing)

font: font-style font-variant font-weight font-size/line-height font-family|caption|icon|menu|message-box|small-caption|status-bar|initial|inherit;

font:caption; browser font used in captioned control
font:icon; browser font used in icon label
font:menu; browser font used in drop-down menu
font:message-box; browser font used in dialog box
font:small-caption;a smaller version of the caption font
font:status-bar; browser font used in the status bar

Reference: font at https://www.w3schools.com/cssref/pr_font_font.asp

Return to css menu

css-6.1 font-family

List several font names, with the most desired first, and the a generic family (web safe font) last
Web safe fonts are commonly installed in most browsers

Examples:
font-family:"Times New Roman", Times, Georgia, serif; serif family
font-family:Arial, Verdana, serif; sans-serif family
font-family:"courier new", "lucida console"; monospace family

Reference for CSS Web Safe Font Combinations at https://www.w3schools.com/cssref/css_websafe_fonts.asp

Example:

font-family:'Times New Roman', Times, Georgia, serif;
font-family:'Courier New', 'Lucida Console';
font-family:Arial, Verdana, serif;
font-family:'Lucida Console', 'Courier New';

Reference: font-family at https://www.w3schools.com/cssref/pr_font_font-family.asp

Return to css menu

css-6.2 font-style

font-style:normal|italic|oblique;
font-oblique; is similar to italic and is less supported

Example:

font-style:normal;
font-style:italic;

Reference: font-style at https://www.w3schools.com/cssref/pr_font_font-style.asp

Return to css menu

css-6.3 font-size

font-size:medium|xx-small|x-small|small|large|x-large|xx-large|smaller|larger|length|initial|inherit;

Relative size: to enable user to change text size in browser, e.g.,
font-size:1em; relative to current font-size of the element
font-size:1ch; relative to width of the "0"
font-size:1vw; relative to 1% of viewport width
font-size:1vh; relative to 1% of viewport height
font-size:1vmin; relative to 1% of viewport's smaller dimension
font-size:1vmax; relative to 1% of viewport's larger dimension
font-size:100%; relative to the parent element
font-size:150%;
font-size:0.875em;1em is 16px

Absolute size: does not allow user to change text size in browser, e.g.,
font-size:20px;

Reference: CSS units at https://www.w3schools.com/cssref/css_units.asp

Example:

font-size:150%;
font-size:1.25em;
font-size:24px;

Reference: font-style at https://www.w3schools.com/cssref/pr_font_font-size.asp

Return to css menu

css-6.4 font-variant

Syntax:
font-variant:normal|small-caps|initial|inherit;
to indicate whether or not display text in small caps font

Example:

font-variant:normal;
font-variant:small-caps;

Reference: font-variant at https://www.w3schools.com/cssref/pr_font_font-variant.asp

Return to css menu

css-6.5 font-weight

Syntax:
font-weight: normal|bold|bolder|lighter|number|initial|inherit;

font-weight:400; is same as font-weight:normal; which is the default value
font-weight:700; is same as font-weight:bold;

Example:

font-weight:bold;
font-weight:normal;
font-weight:lighter;

Reference: font-weight at https://www.w3schools.com/cssref/pr_font_weight.asp

Return to css menu

css-6.6 font-stretch

Syntax:
font-stretch: ultra-condensed|extra-condensed|condensed|semi-condensed|normal|semi-expanded|expanded|extra-expanded|ultra-expanded|initial|inherit;

font-stretch:condensed; to make the text narrower
font-stretch:normal;
font-stretch:expanded; to make the text wider

Example (only works when the font family has width-variant faces.)
font-stretch:condensed; (arial condensed font exists)
font-stretch:normal;
font-stretch:wider; (use normal arial when arial wider font face does not exist)

Reference: font-stretch at https://www.w3schools.com/cssref/css3_pr_font-stretch.asp

Return to css menu

css-6.7 @font-face

To enable using a font that is not installed on the web client, web designer may include the font file on the web server. The css then names the font and provide the url where the font can be found. The font will be downloaded to the web browser when needed.

Example:
@font-face {
font-family: myFirstFont;
src: url(sansation_light.woff);
}

which provides url where the font can be found and name it myFirstFont in font-family.

Reference: @font-face rule at https://www.w3schools.com/css/css3_fonts.asp

Return to css menu

css-7. Image

css-7.5 Opacity / Transparency

opacity:[0,1] 0 is 100% transparent.


opacity=0.25

opacity=0.5

opacity=0.75

opacity=1

Reference: Opacity / Transparencyr at https://www.w3schools.com/css/css_image_transparency.asp

Return to css menu

css-7.6 Overlapping Text/Image

Example: Use position:absolute; to place a block (containing text in this example) on the container.

left:0%;
top:0%;
right:0%;
top:0%;
left:0%;
bottom:0%;
right:0%;
bottom:0%;
top:40%;
left:0%; width:100%;
text-align:center;

Return to css menu

css-7.7 z-index layering

A later element overwrites the earlier elements.

top:40%;
left:0%; width:100%;
text-align:center;
top:38%;
left:0%; width:100%;
text-align:center;
(added after the green text)

Use layering to alter the overwrite order. For example:
z-index:1; is on top of z-index:0;
z-index:0; is on top of z-index:-1;

top:40%;
left:0%; width:100%;
text-align:center;
top:38%;
left:0%; width:100%;
text-align:center;
z-index:-1;
(added after the green text)

The border shows the width:100%

top:30%;
left:0%; width:100%;
text-align:center;
border:dashed green 5px;
box-sizing:border-box;
top:38%;
left:0%; width:100%;
text-align:center;
z-index:-1;
(added after the green text)

Return to css menu

css-8. css Color

css-8.3 Color Theory

Colors for light (RGB)
primary secondary primary secondary primary secondary primary
red
green
blue
red

yellow
cyan
magenta
Colors for ink (CMY)
primary secondary primary secondary primary secondary primary
cyan
magenta
yellow
cyan

blue
red
green
Colors for paint (RYB)
primary secondary primary secondary primary secondary primary
red
yellow
blue
red

orange
green
purple
Colors for paint (RYB)
primary tertiary secondary tertiary primary tertiary secondary tertiary primary tertiary secondary tertiary primary
red 3 2 3 yellow 3 2 3 blue 3 2 3 red
1 3 orange 3 1 3 green 3 1 3 purple 3 1
1 #fc600a 2 #fccc1a 1 #b2d732 2 #347c98 1 #4424d6 2 #c21460 1

Reference: Color Theory at https://www.w3schools.com/colors/colors_theory.asp

Return to css menu

css-8.4 Color representation

Color Names:
web browsers support 140 color names listed at
https://www.w3schools.com/colors/colors_names.asp

rgb(red,green,blue):
3 numbers (0-255) to show amount of red, green blue;
0: black,
255: red / green / blue .
Reference: https://www.w3schools.com/colors/colors_rgb.asp

#ffffff:
3 pairs of hexadecimals (00-ff) to show amount of #ff0000, #00ff00, #0000ff;
Reference: https://www.w3schools.com/colors/colors_hexadecimal.asp

hsl(hue,saturation,lightness):
hue is just another word for color
hue(0-360) in the color circle -
0 is hsl(0,100%,50%),
120 is hsl(120,100%,50%),
240 is hsl(240,100%,50%)
saturation(0-100%) -
0% is hsl(120,0%,50%) grey,
100% is hsl(120,100%,50%) full color
lightness (0-100%) -
0% hsl(0,100%,0%) black,
100% hsl(0,100%,100%) white,
Reference at https://www.w3schools.com/colors/colors_hsl.asp

Return to css menu

css-8.5 Color conversion

Color Converter: is at https://www.w3schools.com/colors/colors_converter.asp

Color picker: at https://imagecolorpicker.com/en/ : Upload image or provide url. Then click on image to get the html codes for the color.

Return to css menu

css-8.6 rgba - opacity

Syntax:
rgba(red, green, blue, alpha)

alpha = 0 - fully transparent
alpha = 1.0 - fully opaque

Example:

rgba(165,42,42,0.25) rgba(165,42,42,0.5) rgba(165,42,42,0.75) rgba(165,42,42,1)

Reference: alpha - color opacity at https://www.w3schools.com/css/css_colors.asp

Return to css menu

css-9. Background

css-9.1 background

background is shorthand for
background-color
background-image
background-position
background-size
background-repeat
background-origin
background-clip
background-attachment

Reference: background at https:www.w3schools.com/cssref/css3_pr_background.asp

css-9.2 background-color

Syntax:
background-color: color|transparent|initial|inherit;

background-color:transparent; is default

Example

background-color:coral; background-color:rgb(165,42,42); background-color:rgba(165,42,42,0.2); background-color:#da70d6;

Reference: background-color at https://www.w3schools.com/cssref/pr_background-color.asp

Return to css menu

css-9.3 background-image:url()

Syntax:
background-image: url("url-1"), url("url-2"), ...; |none; |initial; |linear-gradient(); |radial-gradient(); |repeating-linear-gradient(); |repeating-radial-gradient(); |inherit;

background-image:none; is default

Example

../images/logo-caritas.jpg
opacity:0.5;

Reference: background-image at https://www.w3schools.com/cssref/pr_background-image.asp

Return to css menu

css-9.4 background-image:linear-gradient()

Syntax:
background-image: linear-gradient(direction, color-stop1, color-stop2, ...);

direction, a starting point and a direction, e.g., to top right or 0deg (clockwise angle)
color-stop a color value followed optionally by a stop position (in % or length unit)

Syntax (default direction from top at 0% in equal steps to bottom at 100%):
background-image: linear-gradient(color1, color2, ...);

Example of linear-gradient with direction description

background-image:linear-gradient(to bottom right, red, green, blue);
height:200px; width:300px;

Example of linear-gradient with clockwise angle

background-image:linear-gradient(90deg, red 0%, blue 70%, green 100%);
height:200px; width:300px;

Example of linear-gradient with opacity < 1

background-image:linear-gradient(180deg, rgba(255,0,0,0.25) 0%, rgba(0,0,255,0.25) 100%);
height:200px; width:300px;

Reference: linear-gradient at https://www.w3schools.com/cssref/func_linear-gradient.asp

Return to css menu

css-9.5 background-image:radial-gradient()

Syntax:
background-image: radial-gradient(shape size at position, start-color, ..., last-color);

shape=ellipse(default)|circle

size=farthest-corner(default)|fartest-side|closest-corner|closest-side

position defines the position (default is center)

color-stop a color value followed optionally by a stop position (in % or length unit)

Example of radial-gradient with default ellipse and opacity

background-image:radial-gradient(rgba(255,0,0,0.25),
rgba(0,255,0,0.25),
rgba(0,0,255,0.25));
height:200px; width:300px;

Example of radial-gradient with circle

background-image:radial-gradient(circle,
red 30%,
green 70%,
blue 100%);
height:200px; width:300px;

Example of radial-gradient

background-image:radial-gradient(closest-side at 40% 50%,
rgba(255,0,0,0.25),
rgba(0,255,0,0.25),
rgba(0,0,255,0.25));
height:200px; width:300px;

Reference: radial-gradient at https://www.w3schools.com/cssref/func_radial-gradient.asp

Return to css menu

css-9.6 repeating-linear-gradient()

Syntax:
background-image: repeating-linear-gradient(angle | to side | to corner, color-stop1, color-stop2, ...);

angle: 0deg - 360deg, default 180deg, clockwise angle

to side: to bottom|top|left|right,

to corner: to name 2 adjacent sides,

color-stop a color value followed optionally by a stop position (in % or length unit)

Example of linear-gradient with opacity < 1

background-image:linear-gradient(180deg, rgba(0,255,255,0.25) 0%, rgba(0,255,255,0.25) 10%);
height:200px; width:300px;

Example of linear-gradient with opacity < 1

background-image:repeating-linear-gradient(180deg,
rgba(255,0,0,0.25) 0%,
rgba(0,255,0,0.25) 10%,
rgba(0,0,255,0.25) 20%,
rgba(255,0,0,0.25) 30%);
height:200px; width:300px;

Reference: repeating-linear-gradient at https://www.w3schools.com/cssref/func_repeating-linear-gradient.asp

Return to css menu

css-9.7 background-image:repeating-radial-gradient()

Syntax:
background-image: repeating-radial-gradient(shape size at position, start-color, ..., last-color);

shape=ellipse(default)|circle

size=farthest-corner(default)|fartest-side|closest-corner|closest-side

position defines the position (default is center)

color-stop a color value followed optionally by a stop position (in % or length unit)

Example of radial-gradient with default ellipse and opacity

background-image:repeating-radial-gradient(rgba(255,0,0,0.25),
rgba(0,255,0,0.25) 5%,
rgba(0,0,255,0.25) 10%);
height:200px; width:300px;

Example of radial-gradient with default ellipse and opacity

background-image:repeating-radial-gradient(rgba(255,0,0,0.25),
rgba(0,255,0,0.25) 5%,
rgba(0,0,255,0.25)) 10%,
rgba(255,0,0,0.25) 15%);
height:200px; width:300px;

Example of radial-gradient with default ellipse and opacity

background-image:repeating-radial-gradient(rgba(255,0,0,0.25),
rgba(0,255,0,0.25) 5%,
rgba(0,0,255,0.25)) 10%,
rgba(255,0,0,0.25) 15%);
height:200px; width:300px;

Reference: repeating-radial-gradient at https://www.w3schools.com/cssref/func_repeating-radial-gradient.asp

Return to css menu

css-9.8 background-clip

background-clip defines how far the background should extend within an element.

Syntax:
background-clip: border-box|padding-box|content-box|initial|inherit;

background-clip: padding-box; is default

Example: (1)border-box (2)padding-box (3)content-box (4)default

(1)background-clip:border-box;
(2)background-clip:padding-box;
(3)background-clip:content-box;
(4)background-clip:default to border-box;
border-radius:100px;

Reference: background-clip at https://www.w3schools.com/cssref/css3_pr_background-clip.asp

Return to css menu

css-9.9 background-repeat

Syntax:
background-repeat: repeat|repeat-x|repeat-y|no-repeat|space|round|initial|inherit;

background-repeat:repeat;is default, clip last repeating image if it does not fit

background-repeat:repeat-x/y;repeat in x/y direction only

background-repeat:space;repeat without clipping, evenly distribute space between images

background-repeat:round;repeat without clipping, squish or stretch to fill space

Example: (1)repeat (2)space (3)round (4)default

(1)background-repeat:repeat;
border-radius:60px;
(2)background-repeat:space;
border-radius:60px;
(3)background-repeat:round;
border-radius:60px;
background-repeat:repeat;
border-radius:60px;

Example with background-clip:padding-box; (1)repeat (2)space (3)round (4)default

background-repeat:repeat;
border-radius:60px;
background-clip:padding-box;
background-repeat:space;
border-radius:60px;
background-clip:padding-box;
background-repeat:round;
background-clip:padding-box;
background-repeat:repeat;
border-radius:60px;
background-clip:padding-box;

Reference: background-repeat at https://www.w3schools.com/cssref/pr_background-repeat.asp

Return to css menu

css-9.10 background-size

Syntax:
background-size: auto|length|percentage|cover|contain|initial|inherit;

background-size: auto;is default to display in original size

background-size: length; width height one of the two may be auto

background-size: percentage; width height one of the two may be auto

background-size: cover; resize image to cover the entire container, even if it has to stretch the image or clip at edge

background-size: contain; resize image so that it is fully visible

Return to css menu

background-size: auto; is default to display in original size

Example: auto

background-image:url('../images/CIHE-building.jpg');
background-size:auto;
height:200px; width:300px;
background-image:url('../images/CIHE-building.jpg');
background-size:auto;
background-clip:padding-box;
height:200px; width:300px;


background-size: percentage; width height one of the two may be auto

Example: auto 80%

background-image:url('../images/CIHE-building.jpg');
background-size:auto 80%;
height:200px; width:300px;
background-image:url('../images/CIHE-building.jpg');
background-size:auto 80%;
background-clip:padding-box;
height:200px; width:300px;

background-size: cover; resize image to cover the entire container, even if it has to stretch the image or clip at edge

Example: cover

background-image:url('../images/logo-caritas.jpg');
background-size:cover;
background-repeat:no-repeat;
height:200px; width:300px;

background-size: contain; resize image so that it is fully visible

Example: contain

background-image:url('../images/logo-caritas.jpg');
color:blue;
background-size:contain;
background-repeat:no-repeat;
height:200px; width:300px;

Reference: background-size at https://www.w3schools.com/cssref/css3_pr_background-size.asp

Return to css menu

css-9.11 background-blend-mode

Provide 2 pictures to blend

Syntax:
background-blend-mode: normal|multiply|screen|overlay|darken|lighten|color-dodge|saturation|color|luminosity;

Exmple:

(1) background-blend-mode:normal;
(2) background-blend-mode:multiply;
(3) background-blend-mode:screen;
(4) background-blend-mode:overlay;
(5) background-blend-mode:darken;
(6) background-blend-mode:lighten;

Reference: background-blend-mode at https://www.w3schools.com/cssref/pr_background-blend-mode.asp

Return to css menu

css-9.12 background-origin

Syntax:
background-origin: padding-box|border-box|content-box|initial|inherit;

background-origin: padding-box; is default to start at upper left corner of padding-box

Example: default

background-repeat:no-repeat; padding:10px; box-sizing:border-box; color:yellow; height:200px; width:300px;

background-origin: border-box; to start at upper left corner of border-box

Example: border-box

background-origin:border-box; background-repeat:no-repeat; background-size:cover; padding:10px; box-sizing:border-box; color:yellow; height:200px; width:300px;

background-origin: content-box; to start at upper left corner of content-box

Example: content-box

background-origin:content-box; background-repeat:no-repeat; padding:10px; box-sizing:border-box; color:yellow; height:200px; width:300px;

Reference: background-size at https://www.w3schools.com/cssref/css3_pr_background-origin.asp

Return to css menu

css-9.13 background-position

Syntax:
background-position: left top|left center|left bottom|center top|center center|center bottom|right top|right center|right bottom|initial|inherit;

background-position: left top; is default to start at upper left corner of padding-box

Example:

background-position: left top; background-repeat:no-repeat;
background-position: center center; background-repeat:no-repeat;
background-position: center bottom; background-repeat:no-repeat;

Reference: background-position at https://www.w3schools.com/cssref/css3_pr_background-position.asp

Syntax:
background-position:%-from-left %-from-top| length-from-left length-from-top|initial|inherit;

Example:
background-position:0% 0%; left top corner of image is at left top corner of container

Example:
background-position:20% 10%; means
move 20% of (container_width - image_width) from left, and
move 10% of (container_width - image_width) from top

Example with %-from-left %-from-top:

background-position: 0% 0%;
background-repeat:no-repeat;
background-position: 20% 10%;
background-repeat:no-repeat;
background-position: 40% 20%;
background-repeat:no-repeat;
background-position: 60% 30%;
background-repeat:no-repeat;
background-position: 80% 40%;
background-repeat:no-repeat;
background-position: 100% 50%;
background-repeat:no-repeat;

Return to css menu

css-9.14 background-attachment

Syntax:
background-attachment: scroll|fixed|local|initial|inherit;

background-attachment: with overflow:auto; (1)scroll; is default, (2)local; (3)scroll;, (4)local; will scroll as its container is scroll

(1) background-attachment:scroll;
../images/logo-caritas.jpg
opacity:0.5;
background-repeat:no-repeat;
overflow:auto;
What the poor need the most is not pity but love. They need to feel respect for their human dignity, which is neither less nor different from the dignity of any other human being. (Mother Teresa of Calcutta)
(2)background-attachment:local;
../images/logo-caritas.jpg
opacity:0.5;
background-repeat:no-repeat;
overflow:auto;
What the poor need the most is not pity but love. They need to feel respect for their human dignity, which is neither less nor different from the dignity of any other human being. (Mother Teresa of Calcutta)
(3)background-attachment:scroll;
../images/logo-caritas.jpg
opacity:0.5;
background-repeat:no-repeat;
overflow:auto;
What the poor need the most is not pity but love. They need to feel respect for their human dignity, which is neither less nor different from the dignity of any other human being. (Mother Teresa of Calcutta)
(4)background-attachment:local;
../images/logo-caritas.jpg
opacity:0.5;
background-repeat:no-repeat;
overflow:auto;
What the poor need the most is not pity but love. They need to feel respect for their human dignity, which is neither less nor different from the dignity of any other human being. (Mother Teresa of Calcutta)

Reference: background-attachment at https://www.w3schools.com/cssref/pr_background-attachment.asp

Return to css menu

Project 2

Move all the styles to the head section

Move all the styles to an external css file

Return to css menu

Project 3

Add the following at the end of your work:

Pick 2 picture files of different aspect ratio and with native size not wider than 30% of the width of your screen.

Display each of these these 2 pictures vertically aligned to the right but with the same width.

Display each of these these 2 pictures vertically aligned to the center (between left and right) with the same width.

Display each of these these 2 pictures horizontally aligned and with the same height.

Return to css menu

css-10. user interface with css

A good design of navigation is needed to enable user to look up the desired information in a user friendly manner. Quite sophisticated navigation can be accomplished using css alone.

Navigation can simply be accomplished with a collection of links, which may be list element, div element, etc. which may be enclosed by nav tags in a navigation section inside the body section.

The html element may refer to the css definition using class, e.g.,
<div class="class_name">

In css, the html element is selected
.class_name { ... }

Return to css menu

css-10.1 Navigation bar

Navigation menu may be an unordered list of links.

  1. The selector of the unordered list ul element may be
    ul.class_name { ... }

  2. the selector of the list item li element inside the unordered list may be
    .class_name li { ... }

  3. the selector of the list item li element upon hovering inside the unordered list may be
    .class_name li:hover { ... }

  4. the selector of the link element a inside the unordered list may be
    .class_name li a { ... }, or
    .class_name a { ... }

Return to css menu

css-10.1.1 unordered list

To remove bullets and default browser margin and padding in css, select ul and:

/* ul - removes bullets and default browser margins & padding */
list-style-type: none; 
margin: 0; 
padding: 0;

Then the ul appearance may be redefined in css, select ul and, for example:

/* ul - appearance */
line-height: 1em; 
vertical-align: middle; 
zoom: 1;

Example

Return to css menu

css-10.1.2v Vertical with ul

Navigation may either be vertical or horizontal

li elements are by default blocks, which are therefore vertical and takes up the full width. The position is shown more clearly by defining its appearance

/* ul - appearance */
background-color: #e0e0e0;

Example

A different width may be defined.

/* ul - width for vertical menu */
width: 200px;

A full height vertical menu is

/* ul - height for vertical menu*/
height: 100%;
overflow: auto;

Example

Return to css menu

css-10.1.2h horizontal with li

To convert to display horizontally:

/* li - float for horizontal menu*/
float: left;

Example

Return to css menu

css-10.1.3 li appearance and position

li - appearance

/* li - height */
font-size: large; 

li - position:relative; to provide reference for descendants to use position:absolute;

/* li - height */
position: relative; 

Example with vertical list

Example with horizontal list

Return to css menu

css-10.1.4 list item li upon hovering

To change appearance upon hovering over li, the css selector is li:hover

  1. It is desirable to change the appearance upon hovering

    /* li:hover - change appearance upon hovering*/
    cursor: pointer;
    background: #ffffaa; 
    

Example with vertical list

Example with horizontal list

Return to css menu

css-10.1.4a link a upon hovering

The alternative to change appearance upon hovering over a is to use the css selector a:hover

  1. It is desirable to change the appearance upon hovering

    /* a:hover - change appearance upon hovering*/
    position: relative;
    cursor: pointer;
    background: #ffffaa; 
    

Example with vertical list

Example with horizontal list

Return to css menu

css-10.1.5 link a appearance

  1. The default appearance of a link can be removed

    /* a - removes browser default text-decoration */
    text-decoration: none;
    

Example with vertical list

Example with horizontal list

  1. display:block; makes the whole link area clickable.

    /* a - whole link area clickable */
    display: block;
    
  1. The link appearance may then be redefined, e.g.,

     
    /* a - link appearance*/
    color: #7e2e1f; border: 3px solid #ffffff;
    

Example with vertical list

Example with horizontal list

Return to css menu

css-10.1.6 Current page

The appearance of the current link may be changed to show user where one is at, e.g.:

.current {
background-color: #aaffaa;
}

Example with vertical list

Example with horizontal list

  1. To change hover appearance with the list item except for the current page, the css selector is
    li:hover:not(.current-page_name)
    and add class=".current-page_name" to the li of the current page.
  2. To change hover appearance with the list item except for the current page, the css selector is
    a:hover:not(.current-page_name)
    and add class=".current-page_name" to the a of the current page in the html file.

Example with vertical list

Example with horizontal list

Reference: Navigation at https://www.w3schools.com/css/css_navbar.asp

Return to css menu

css-10.1.7 Exercise

1. Create a vertical menu for your webpage, following the 6 steps in this Section 10.1 and present your answers in a separate file in each of these steps. (In step 2, create the vertical menu only. In step 4, the links should go to different sections of your web page.)

2. Turn the vertical menu into a horizontal menu.

Return to css menu

css-10.2 Dropdown menu

Dropdown menu extends the navigation bar. It may simply be nested links, which may be div or list elements inside a div or list element.

Consider the following example of nesting unordered list of links.

Example

  1. Selecting ul
    1. Selecting the unordered list ul element:
      ul.class_name { ... }

    2. Selecting the descendant unordered list ul element:
      ul.class_name ul { ... }

    3. Selecting the descendant unordered list ul element of descendant list:
      ul.class_name ul ul { ... }

  2. Selecting li
    1. the selector of the list item li element inside the selected list
      .class_name li { ... }
      also includes those li of any descendant list.

    2. the selector of the list item li element upon hovering inside the selected list may be
      .class_name li:hover { ... }
      also includes those li:hover of any descendant list.

  3. the selector of the link element a inside the selected list
    .class_name li a { ... }, or
    .class_name a { ... }
    also includes those a of any descendant list.

Return to css menu

css-10.2.1 Nested list appearance

A. descendant unordered list .class_name ul

Change the appearance for ul.class_name ul in addition to that of ul.class_name:

  1. Select both ul and the decendant ul to remove the bullets and any default browser padding or margin as for the navigation bar above; and

    /* ul.class_name, ul.class_name ul - removes bullets and default browser margins & padding */
    list-style-type: none; 
    margin: 0; 
    padding: 0;
    
  2. define the list appearance as for the navigation bar above

    /* ul.class_name, ul.class_name ul - appearance */
    line-height: 1em; 
    vertical-align: middle; 
    zoom: 1;
    

Example: For both the selected list and its descendants, and after removing bullets and default browsing padding or margin and after defining list appearance, the example list becomes

Return to css menu

css-10.2.2 list vs decendant list appearance

B.1 list item li of descendant list

The desired appearance of the navigation bar versus the dropdown may differ. For example, the navigation bar may be a horizontal list whereas the dropdown may be a vertical list.

Example is a horizontal navigator bar with vertical descendant list.

/* ul.class_name > li - float for horizontal menu*/
float: left;

css-10.2.3 li - appearance and position

li - appearance

ul.class_name li selects all descendant (child, grandchild, etc.) list items

/* ul.class_name li - appearance */
font-size: large; 
position: relative; 

li - position

position: relative provides reference for use of position: absolute by its descendants.

Return to css menu

css-10.2.4 li upon hovering

B.2 list item li:hover of descendant list

.class_name li:hover has already selected all descendant list items upon hovering.

/* ul.class_name li:hover - change appearance upon hovering*/
cursor: pointer;
background: #ffffaa; 

After changing hover appearance, the list becomes:

Return to css menu

css-10.2.5 link a appearance

C. link a of descendant list

.class_name a has already selected all descendant a links.

 
/* ul.class_name a - link appearance*/
text-decoration: none;
display: block;
color: #7e2e1f; 
border: 3px solid #ffffff;

After removing default link appearance, making whole link area clickable, and defining the link appearance, the list example becomes

Return to css menu

css-10.2.6 Hide / show upon hover

D. Hide and display upon hovering

  1. /* Hide the sub menus */
    .class_name ul {
    display: none;
    }
    
  2. /* display ul element of li upon hovering li */
    .class_name li:hover ul {
    display: block; z-index: 10
    }
    

Return to css menu

css-10.2.7 sub-menu appearance

E.1 sub-menu additional appearance

/* ul.class_name ul - sub-menu appearance */
.class_name ul {
background-color: ???; 
min-width: 200px; 
}

Horizontal menu example

Vertical menu example

Return to css menu

css-10.2.8 sub-menu position

E.2 sub-menu position

Horizontal menu with dropdown sub-menu:

/* ul.class_name ul - sub-menu position */
.class_name ul {
position: absolute; 
top: 100%; left: 0; 
}

Vertical menu with dropdown sub-menu:

/* ul.class_name ul - sub-menu position */
.class_name ul {
position: absolute; 
top: 0; left: 100%; 
}

Return to css menu

css-10.2.9 sub sub-menu position

E.3 sub sub-menu position example

Let us add a sub sub menu under HTML Elements:

Horizontal menu with dropdown

Vertical menu with dropdown

In the horizontal menu, it is difficult to distinguish the sub sub menu from the sub menu because they have the same appearance. To distinguish their appearances:

/* sub sub-menu position */
.class_name ul ul {
position: absolute;
top: 0; left: 100%;
}

Example list become

Reference: Dropdowns at https://www.w3schools.com/css/css_dropdowns.asp

Return to css menu

css-10.2.10 Exercise

1. Create a horizontal menu with dropdown sub-menu and sub sub-menu for your webpage, following the 8 steps in this Section 10.2 and present your answers in a separate file in each of these steps. (The links should go to different sections of your web page.)

2. Turn into a vertical menu with dropdown sub-menu and sub sub-menu.

Return to css menu

Project 4

1. Create a vertical menu for your webpage

2. Turn the menu into a horizontal menu

Do this exercise in 6 steps as in Section 10.1 above

Return to css menu

css-10.3 Responsive Web Design

RWD adapts the content to fit any device
by using css and html only to resize, hide, shrink, enlarge, or move the content
to make the web page look good and be easy to use on different devices.

Example:
a single column on mobile phone
side navigation on tablet
3 columns on even wider screen

Reference: Responsive Web Design at https://www.w3schools.com/css/css_rwd_intro.asp

Return to css menu

css-10.3.1 viewport

Viewport is the user's visible area of a web page, which varies with different devices.

In head section:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
sets the width of the page to follow the screen-width of the device,
and sets the initial zoom level when the page is first loaded by the browser.

UI guidelines to avoid the need to scroll horizontally or to zoom out

  1. Large fixed width elements should be avoided.
  2. Instead, adjust content to fit within width of viewport.
  3. Content should not depend on a particular viewport width to render well.
  4. Large absolute css widths for html elements or large absolute positioning values should be avoided, because the element may fall outside the viewport on a small device

Reference: Responsive Web Design - Viewport at https://www.w3schools.com/css/css_rwd_viewport.asp

Return to css menu

css-10.3.2 Responsible grid-view

A responsible web design can be achieved with presenting contents in single or 2 to 3 columns depending on the width of the viewport. A grid view with 12 equal-width columns provides flexible control to split the page into 2 or 3 equal or unequal columns of div elements.

Prior to calculating the width of the columns, ensure padding and border are included in the total width and height of the elements:

* { box-sizing: border-box; }
.row::after {
  content: "";
  clear: both;
  display: table;
}

[class*="c"] {
  float: left;
  padding: 15px;
  border: 1px solid blue;
}

.col-1 {width: 8.33%;}
.col-2 {width: 16.66%;}
.col-3 {width: 25%;}
.col-4 {width: 33.33%;}
.col-5 {width: 41.66%;}
.col-6 {width: 50%;}
.col-7 {width: 58.33%;}
.col-8 {width: 66.66%;}
.col-9 {width: 75%;}
.col-10 {width: 83.33%;}
.col-11 {width: 91.66%;}
.col-12 {width: 100%;}

Following HTML example of a 25% left column and a 75% right column:

<div class="row">
<div class="col-3"> ... </div>
<div class="col-9"> ... </div>
</div>

has the same effect of produces the following:

This is a test of running 2 columns. 5. Modern Society will find no solution to the ecological problem unless it takes a serious look at its lifestyles. (Pope John Paul II).

Reference: RWD Grid-view at https://www.w3schools.com/css/css_rwd_grid.asp

Return to css menu

css-10.3.3 Media query

@media query enables to include some css properties only if the condition stated in the query is true.

@media only screen and (max-width: 768px) {
 [class*="col-"] {
   width: 100%;
 }
}

will change col- width in above example to 100%

2 columns changes to a single column with narrow viewport. I have not the shadow of a doubt that any man or woman can achieve what I have, if he or she would make the same effort and cultivate the same hope and faith. (Mohandas Karamchand Gandhi)

Reference: RWD Media Query at https://www.w3schools.com/css/css_rwd_mediaqueries.asp

Return to css menu

css10.3.4 Exercise

1. Create a webpage using css file with 2 columns (submit both html and css files)

2. Make a copy of the two files (with different file names), add the media query so that the webpage is single column for narrow screen (say 600px), but will become double column for wider screen.

Return to css menu

css-10.04 responsive flex menu

In css file:

/* responsive navigation menu start */
nav ul {
	background-color:var(--dark);
	list-style:none;
	display:flex;
	flex-direction:column;
	font-size:small;
	z-index:2;
}
nav ul li:hover {
	font-size:medium; 
	background-color:var(--light)
}
.arrow {
	font-family:FontAwesome;
	float:right;
}
.arrow-down::after {
	content:"\f107";
}
.arrow-right::after {
	content:"\f105";
}
nav ul li a {
	padding:.1em .4em;
	display:block;
	text-decoration:none;
	color:#ffffff;
}
nav ul li {
	position:relative;
	flex:1 0 auto;
}
.has-children ul, .has-children ul .has-children ul {
	display:none;
	width:100%;
	position:absolute;
}
@media only screen and (max-width:680px) {
	.arrow-down::after {
	content:"\f107"
	}

    nav ul {
		width:160px;
	}
	.has-children ul, .has-children ul .has-children ul {
		top:0;
		left:100%;
	}
}
@media only screen and (min-width:680px) {
	nav ul {
		flex-direction:row;
		justify-content:space-between;
	}
	.has-children ul .has-children ul {
        top:0;
		left:100%;
	}
}

nav ul li:hover ul, .has-children ul .has-children:hover ul  {
	display:flex;
	flex-direction:column;
}
/* responsive navigation menu end */
	

In html file:

	

      <nav>
        <ul>
          <li class="has-children"><a href="#css-01">Define <span
                class="arrow arrow-down"></span> </a>
            <ul>
              <li><a href="#css-0101">1.1 Syntax</a></li>
              <li><a href="#css-0102">1.2 Inline css</a></li>
              ....
            </ul>
          </li>
          <li class="has-children"><a href="#css-02">Selector <span
                class="arrow arrow-down"></span> </a>
            <ul>
              <li><a href="#css-0201">2.1 class vs id</a></li>
              <li><a href="#css-0202">2.2 Combinator</a></li>
              <li><a href="#css-0203">2.3 pseudo-class</a></li>
              <li class="has-children"><a href="#css-0204">2.4
                  pseudo-element <span class="arrow arrow-down
                    arrow-right"></span> </a>
                <ul>
                  <li><a href="#css-020401">2.4.1 ::first-letter/line</a></li>
                  <li><a href="#css-020402">2.4.2 ::before/after</a></li>
                  <li><a href="#css-020403">2.4.3 ::selection</a></li>
                </ul>
              </li>
              <li><a href="#css-0205">2.5 attribute selector</a></li>
              <li><a href="#css-0206">2.6 exercise</a></li>
            </ul>
          </li>
		  ....
        </ul>
      </nav>		

	  

Return to css menu

css-10.05 collapsible menu

In css file

/* collapsible navigation menu start */
:root{
	box-sizing:border-box;
	--primary :#cccccc;
	--hover-color:#fdd052;
	--dark:#0c3c63;
	--light:#6eadbd; 
	--header-bg:var(--dark);
}
*, *::after, *::before{
	box-sizing:inherit;
	margin:0;
	padding:0;
}

.header{
	background-color:var(--dark);
	position:sticky;
	width:100%;
	z-index:1;
}
.header ul.menu{
	background-color:var(--dark);
	list-style:none;
	overflow:hidden;
}
.header ul a{
	display:block;
	padding:.1em .4em;
	text-decoration:none;
	color:#ffffff;
}
.header .logo {
	float:left;
	text-decoration:none;
	display:block;
	color:var(--light);
	font-size:2em;
	padding:10px 20px;
}
.header>.menu {
	clear:both;
	max-height:0;
	transition:max-height .2s ease-out;
} /* collapse (hide) the ul with class="menu" */
.header>ul a:hover{
	font-size:large; 
	background-color:var(--light);
	color:var(--hover-color);
}
.header .menu-icon {
    padding:28px 20px;
	position:relative;
	float:right;
	cursor:pointer;
} /* define the label area, which is bound to the input */
.header .menu-icon .nav-icon{
	background:var(--light); 
    display:block;
	height:2px;
	width:18px;
	position:relative;
	transition:background .2s ease-out;
	top:0px;
} /* hamburger middle line */
.header .menu-icon .nav-icon:before {
	background:var(--light); 
    content:"";
    display:block;
	height:100%;
	width:100%;
	position:relative;
	transition:all .2s ease-out;
	top:5px;
} /* hamburger bottom line */
.header .menu-icon .nav-icon:after {
	background:var(--light); 
    content:"";
    display:block;
	height:100%;
	width:100%;
	position:relative;
	transition:all .2s ease-out;
	top:-7px;
} /* hamburger top line */
.header .menu-btn {
    display:none;
}   /* hidden the checkbox */
.header .menu-btn:checked ~ .menu {
	max-height:440px;
	width:200px;
}   /* upon checking the input element, display the ul element with class="menu" */
.header .menu-btn:checked ~ .menu-icon .nav-icon {
	background:transparent;
}   /* hamburger to cross: remove middle */
.header .menu-btn:checked ~ .menu-icon .nav-icon:before {
	transform:rotate(-45deg);
	top:0;
}   /* hamburger to cross: rotate :before line counter-clockwise */
.header .menu-btn:checked ~ .menu-icon .nav-icon:after {
	transform:rotate(45deg);
	top:-2px;
}   /* hamburger to cross: rotate :after line clockwise */
/* collapsible navigation menu end */
	

In html file:

    <header class="header"> 
	  <a href="#" class="logo">CIHE</a> 
      <input class="menu-btn" id="menu-btn" type="checkbox"> 
      <label class="menu-icon" for="menu-btn">
        <span class="nav-icon"></span>
      </label>
      <ul class="menu">
        <li class="has-children"><a href="#css-01">Define <span
              class="arrow arrow-down"></span> </a> </li>
        <li class="has-children"><a href="#css-02">Selector <span
              class="arrow arrow-down"></span> </a> </li>
        <li class="has-children"><a href="#css-03">Box/layout <span
              class="arrow arrow-down"></span> </a> </li>
        <li class="has-children"><a href="#css-05">Text <span
              class="arrow arrow-down"></span> </a> </li>
      </ul>
    </header>
	

Return to css menu

css-10.06 Responsive and collapsible

The sticky menu in this webpage is written with the following:

In css file

:root{
	box-sizing:border-box;
	--dark:#0c3c63;
	--medium:#6eadbd; 
	--light:#ffffff;
	--plain:#ffffff;
	--header-bg:var(--dark);
	--hover-color:var(--medium);
	--primary:var(--dark);
}

*, *::after, *::before{
	box-sizing:inherit;
	color:var(--primary);
}
body{
	font-family:geneva, sans-serif; 
	font-size:medium;
	box-sizing:border-box;
	margin:0;
	padding:0;
	color:var(--primary);
}

h1::before, h2::before, h3::before {
content: '\A'; white-space: pre; }

.page-width {
margin:auto;
max-width:800px;
}
.right {
	text-align: right;
	font-size: 0.8em;
}


/* BEGIN RESPONSIBE COLLAPSABLE MENU DESIGN */
div.fixed {
position: sticky;
top: 0px;
width:100%;
z-index:2;
}

header{
	background: var(--header-bg);
	margin:0;
	padding:0;
	padding-left:1em;
	font-size:small;
}
header *{
	margin:0;
	padding:0;
}	
.branding-logo{
	color:var(--light);
	text-decoration:none;
	font-size:larger;
}
.navbar{
	display:flex;
	justify-content:space-between; /* branding-logo on left, hamburger/menu on right */
	align-items:center;
}
.menu{
	display:flex;
	flex-direction:row; /* place menu list items in a row */
}
.menu li{
	list-style:none; /* remove bullet before list item */
}
.menu li a {
	display:block;
	text-decoration:none; /* remove browser default format for a link */
	padding:0.1em 0.3em;
}
.menu li a:not(.active){
	color:var(--light);
}
.menu li a.active {
	color:var(--medium);
}

.menu > li > a{
	font-size:small;
}
/* styling submenu */
.has-dropdown{ /* parent of submenu */
	position:relative; /* set parent of submenu to relative */
}
.submenu{
	position:absolute; /* absolute inside a relative parent */
	right:0;
	background-color:var(--header-bg);
	/* 
	white-space:nowrap; 
	*/
	min-width:10em;
	/* hide submenus */
	opacity:0;
	transform:scaleY(0);
	transform-origin: top center;
}
.submenu .submenu{
	right:100%;
	top:0;
}
.menu > li:hover > a,
.submenu > li:hover > a{
	color:var(--medium);
	font-size:larger;
}


/* Arrow */
.arrow{
	width:0.5em;
	height:0.5em;
	display:inline-block;
	vertical-align:middle;
	border-left:0.15em solid var(--light);
	border-bottom:0.15em solid var(--light);
	transform: rotate(-45deg);
	margin-top:-.25em;
	transition: transform 100ms ease-in-out;
}

/* reveal submenu */
.menu > li:hover > a + .submenu,
.submenu > li:hover > a + .submenu{
	opacity:1;
	transform:scaleY(1);
}

/* animate arrows */
.menu > li:hover > a > .arrow,
.submenu > li:hover > a > .arrow{
	transform:rotate(225deg);
}

/* responsive */
@media only screen and (max-width:36em) {
	header{
		position:relative;
	}
	.menu{
		flex-flow:column;
		position:absolute;
		background:var(--dark);
		top:100%;
		left:0;
		
		/* hide menu initially */
		opacity:0;
		transform:scaleY(0);
		transform-origin:top center;
		transition: 0.4s transform ease-in-out; 
	}
	.submenu, .submenu .submenu{
		top:0;
		left:100%;
		z-index:1;
	}
	/* hamburger */
	.hamburger {
		display:inline-block;
		cursor:pointer;
	}
	.hamburger div{
		width:1.4em;
		height:0.2em;
		margin:0.2em 0.8em;
		background-color:var(--light);
		position: relative;
		transition:0.4s transform ease-in-out;
	}

	/* hamburger close */
	.close .bar1{
		transform:rotate(45deg) translate(.1em,.45em);
		transition:0.4s transform ease-in-out;
	}
	.close .bar2{
		opacity:0;
	}
	.close .bar3{
		transform:rotate(-45deg) translate(.1em,-.45em);
		transition:0.4s transform ease-in-out;
	}
	
	/* reveal menu */
	.menu > li > a{
		line-height:1.4em;
	}
	#input-hamburger:checked + .menu{
		position: absolute;
		opacity:1;
		transform:scaleY(1);
	}
}
/* END RESPONSIBE COLLAPSABLE MENU DESIGN */	
    

In html file:

	
    
<header> <nav class="navbar"> <div><a href="HTML-tutorial.html" class="branding-logo">HTML</a> <a href="CSS-tutorial.html" class="branding-logo">CSS</a> <a href="JS-tutorial.html" class="branding-logo">JS</a> <a href="PHP-tutorial.html" class="branding-logo">PHP</a> </div> <label for="input-hamburger" class="hamburger"> <div class="bar1"></div> <div class="bar2"></div> <div class="bar3"></div> </label> <input id="input-hamburger" hidden="" type="checkbox"> <ul class="menu"> <li class="has-dropdown"><a class="active" href="CSS-tutorial.html#css-01">Define <span class="arrow"></span> </a> <ul class="submenu"> <li><a href="CSS-tutorial.html#css-0101">1.1 Syntax</a></li> <li><a href="CSS-tutorial.html#css-0102">1.2 Inline css</a></li> <li><a href="CSS-tutorial.html#css-0103">1.3 Internal css</a></li> <li><a href="CSS-tutorial.html#css-0104">1.4 External css</a></li> <li><a href="CSS-tutorial.html#css-0105">1.5 CSS validation</a></li> <li><a href="CSS-tutorial.html#css-0106">1.6 exercise</a></li> </ul> </li> ... <li class="has-dropdown"><a href="CSS-tutorial.html#css-12">Framework<span class="arrow"></span></a> <ul class="submenu"> <li><a href="CSS-tutorial.html#css-1201">12.1 Bootstrap</a></li> <li><a href="CSS-tutorial.html#css-1202">12.2 w3.css</a></li> <li><a href="CSS-tutorial.html#css-1203">12.3 Cheat sheet</a></li> <li class="has-dropdown"><a href="CSS-tutorial.html#css-13">Project<span class="arrow"></span></a> <ul class="submenu"> <li><a href="CSS-tutorial.html#css-1301">13.1 Project</a></li> </ul> </li> </ul> </li> </ul> </nav> </header> </div> <script> const hamburger = document.querySelector(".hamburger"); hamburger.addEventListener("click", function(){ this.classList.toggle("close"); }); </script>

Example: Check the sticky menu in this webpage

Tutorial

Example tutorials are:

Responsive multi level dropdown men with css, animated hamburger
https://www.youtube.com/watch?v=pro3ceh2YZ8

Responsive menu with hamburger
https://www.youtube.com/watch?v=sjrp1FEHnyA

Responsive menu with arrow
https://www.youtube.com/watch?v=a0Zz9oVGgJc

Return to css menu

css11. More

css11.1 how-to

Reference: How to at https://www.w3schools.com/howto/

Return to css menu

css11.2 Bootstrap

Reference: Bootstrap 4 at https://www.w3schools.com/bootstrap4/bootstrap_get_started.asp

Return to css menu

css11.3 W3.CSS

Either download w3.css from https://www.w3schools.com/w3css/w3css_downloads.asp or link to w3.css:

<!DOCTYPE html>
<html>
<title>W3.CSS</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<body>
</body>
</html>

Reference: W3.CSS at https://www.w3schools.com/w3css/default.asp

Return to css menu

css11.4 Reference

Interactive cheat sheet: CSS cheat sheet at https://htmlcheatsheet.com/css/

Return to css menu

css11.5 Project

css11.5.1 Project

The website is written in html5 language, with comments to enable other developer to maintain the website. (2 points)

All styling instructions are in a separate css file, with comments to enable other developer to maintain the website. (2 points)

No in-line or internal styling in the entire html file. (2 points)

The website may be your personal website or an organization/interest group you are starting with an attractive title. (2 points)

Each topics has a major heading, followed by one or more paragraphs. (2 points)

The first topic is an introduction about yourself/your organization. (points)

Create a topic or sub-topic with suitable heading or sub-heading appropriate to webpage of yourself or your organization to contain one small picture when viewed on a narrow screen (phone), but changes to a different and wider picture when viewed on a wide screen (laptop). (2 points)

The information in one of the topic is in 2 columns: the left column shows a picture; the right column is in text. The information is shown in 2 columns when viewed on a wide screen (laptop), but changes to a single column when viewed on a narrow screen (phone). (6 points)

At least one topic has, in addition to a major heading, also sub-headings, and there is at least one paragraph under each sub-heading. (4 points)

Create another topic or sub-topic with suitable heading or sub-heading appropriate to webpage of yourself or your organization to contain a link to download a file. (2 points)

Create another topic or sub-topic with suitable heading or sub-heading appropriate to webpage of yourself or your organization to contain an audio control to listen to.(2 points)

Create another topic or sub-topic with suitable heading or sub-heading appropriate to webpage of yourself or your organization to contain a video with control to watch. (2 points)

Use a tiled background with a suitable picture file which does not make it difficult to view the text and pictures. (2 points)

Create another topic with suitable title appropriate to webpage of yourself or your organization to contain a form for a user to submit name, email address, and phone number, for which each field is mandatory. The phone number format is shown, and the form will check whether the phone number filled in conforms to this format. It will check whether the email address is indeed an email address. Clicking submit when any field is filled improperly will not submit but will instead indicate the error. (6 points)

There is a horizontal navigation menu with links to every main heading. (6 points)

There is a dropdown sub-menu for the sub-headings from each main heading. (6 points)

Add JavaScript with 2 buttons for picture A and B respectively. Clicking one button for picture A will display picture A, but clicking the other button for picture B will display picture B instead. (6 points)

Return to css menu