HTML AND CSS

WEBSITE BASICS, HTML 5, CSS 3, WEB 2.0 

Web Essentials: Clients, Servers and Communication – The Internet – Basic Internet protocols – World wide web – HTTP Request Message – HTTP Response Message – Web Clients – Web Servers. HTML5 – Tables – Lists – Image – HTML5 control elements – Semantic elements – Drag and Drop – Audio – Video controls. CSS3 – Inline, embedded and external style sheets – Rule cascading – Inheritance – Backgrounds – Border Images – Colors – Shadows – Text – Transformations – Transitions – Animations. 



Web Essentials

Clients, Servers and Communication

Application program which is running in an end user machine is said to be a client. An application program which is running on a dedicated machine to which a client can request for a resource is said to be a server. The process of interaction between the client and the server is said to be a communication. It happens with the help of various communication protocols.

The Internet

  • The Internet is the global system of interconnected computer networks that use the Internet protocol suite (TCP/IP) to link devices worldwide
  •  It is a network of networks that consists of private, public, academic, business, and government networks of local to global scope, linked by a broad array of electronic, wireless, and optical networking technologies
  • The Internet carries a vast range of information resources and services, such as the inter-linked hypertext documents and applications of the World Wide Web (WWW), electronic mail, telephony, and file sharing

Basic Internet protocols

  • HTTP(Hyper Text Transfer Protocol)
  • DNS (Domain Name System)
  • FTP (File Transfer Protocol)
  • SMTP(Simple Mail Transfer Protocol)
  • TELENT
  • ARP (Address Resolution Protocol)
  • DHCP (Dynamic Host Configuration Protocol)
  • TCP(Transmission Control Protocol)
  • IP (Internet Protocol)

World Wide Web(WWW)

  • 1989 – Tim Berners-Lee
  • WWW is a system of interlinked hypertext documents accessed via internet
  • With a web browser, a user views web pages that may contain text, images, and other multimedia contents and navigates between them using hyperlinks

Web Page

  • A Web page is a hypertext document.
  • This means some parts of displayed text are links which can be activated (usually by a click of the mouse) to fetch a new Web page
  • Web page file extensions as follows:
    • .html
    • .jsp
    • .aspx
    • .asp
    • .php
    • Admin

HTTP

  • HTTP is a  client-server  protocol which allows the fetching of resources, such as HTML documents
  • It is the foundation of any data exchange on the Web
  • Clients and servers communicate by exchanging individual messages
  • The messages sent by the client, usually a Web browser, are called requests and the messages sent by the server as an answer are called responses.

HTTP Request Message

It is a message created by a http client running on a client application program to the server for requesting a resources like web page and other documents in the proper format.

HTTP Response Message

It is a message created by a http server running on a server machine to the client containing the requested resources as response or other messages in the proper format.



Web Clients

  • The Web client is a client-side component
  • Client-side components are typically computer applications running on a user's computer and connect to a server
  • A web client consists of two parts:
  • Dynamic web pages containing various types of markup language (HTML, XML, and so on), which are generated by web components running in the web tier
  • A web browser, which renders the pages received from the server
  • A web client is sometimes called a thin client

Web Servers

  • A web server is server software, or hardware dedicated to running said software, that can satisfy World Wide Web client requests
  • A web server can, in general, contain one or more websites
  • The primary function of a web server is to store, process and deliver web pages to clients
  • The communication between client and server takes place using the Hypertext Transfer Protocol (HTTP)

HTML5

  • Hyper Text Markup Language version 5 is used to create a webpage.
  • HTML5 is the newest version of HTML, only recently gaining partial support by the makers of web browsers.
  • It incorporates all features from earlier versions of HTML, including the stricter XHTML.
  • It adds a diverse set of new tools for the web developer to use.
  • It is still a work in progress.  No browsers have full HTML5 support

Structure of HTML5

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
</head>
<body>
//content of the document
</body>
</html>

HTML Tags


Tag Name

Purpose

<html>

It is the root of the html document which is used to specify that the document is html.

<head>

To contain all the head element in the html file. It contains the title, style, meta, … etc

<body>

To define the body of html document. It contains image, tables, lists, … etc.

<title>

To define the title of html document

<h1>,<h2>… <h6>

Heading Tags: It is used to define the heading of html document

<p>

to define paragraph content in html document

<b>

to specify bold content in html document

<table>,<tr>,<td><th>

to create a table in html document

<i>

to write the content in italic format

<u>

to set the content underline

<a>

to link one page to another page

<ol>, <ul>, <li>

to list the content(ordered / unordered)

<br>

to break the line

<img>

to add image element in html document

<link>

to link the content from external source

<hr>

to display the horizontal line in html document

<meta>

to specify the page description. For example: last modifier, authors, … etc.

<form>,<input>,

<select>,<option>

to create html form



Tables

  • Tables in the web page can be displayed using <table> tag.
  • <th>,<tr> and <td> are the some of the sub elements of <table> element
  • Example
            <table>
<tr>
<th>Roll Number</th>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>101</td>
<td>Raja</td>
<td>20</td>
</tr>
<tr>
<td>102</td>
<td>Kannan</td>
<td>22</td>
</tr>
<tr>
<td>103</td>
<td>Madan</td>
<td>21</td>
</tr>
    </table>

Lists

  • HTML lists are used to present the list of items in the proper format.
  • This is achieved by <ul>, <ol> and its sub element <li> tags
  • There are two ways to present the list of items in a webpage
    • Ordered List using <ol> tag
    • Unordered List using <ul> tag
  • Example of Ordered List
                <ol>
<li>CSE</li>
<li>ECE</li>
<li>EEE</li>
<li>MECH</li>
</ol>
  • Example of unordered list
                <ul>
<li>Library</li>
<li>Wi-Fi</li>
<li>Gym</li>
<li>Sports Complex</li>
</ul>

Image

  • Images can be displayed on the web page using <img> tag
  • It has the following attributes
    • src  - image source file name
    • alt - show alternate text if image is not available
    • height - change the height of the image
    • width - change the width of the image
  • Example
        <img src="nature.jpg" alt="Nature Image" height="200 px" width="200 px">

HTML5 control elements

Semantic elements

Drag and Drop

Audio Controls

Video controls

CSS3

Cascading Style Sheet(CSS) is a style sheet language for designing the contents of the web page. It separates the presentation and contents of the webpage.

CSS Types

  • Inline
  • Embedded
  • External style sheets

Inline Style Sheet:

When a style sheet is defined for a particular tag, which affects only that tag, is said to be inline style sheet.
It is added to tag or element using style attribute.

Example:

<h1 style="color:red;">Welcome</h1>

Embedded Style Sheet:

When a style sheet is embedded into a html code using <style> element is said to be the embedded style sheet. This type of style sheet affects only that particular page.

Example:

<!DOCTYPE html>
<html>
    <head>
        <style>
        h1
        {
            color:red;
        }
        </style>
    </head>
    <body>
        <h1>Welcome</h1>
    </body>
</html>

External Style Sheet:

When a style sheet is created as external file with .css extension and is linked to a html code using <link> tag is said to be a external style sheet.

Example:

mystyle.css

h1
{
    color:red;
}

sample.html

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="mystyle.css">
    </head>
    <body>
        <h1>Welcome</h1>
    </body>
</html>

Importing Style Sheet

  • The @import rule is another way of loading an external style sheet
  • The @import statement instructs the browser to load an external style sheet and use its styles.
  • You can use it in two ways:

1. Within header

<style>
    @import url("css/style.css");
    p {
        color: blue;
        font-size: 16px;
    }
</style>

2. within another style sheet

@import url("css/layout.css");
@import url("css/color.css");
body {
    color: blue;
    font-size: 14px;
}

CSS SYNTAX


CSS rules have two main parts, a selector and one or more declarations:

selector
{
property:value;
property:value;
}

Example:


h1
{
color:red;
font-size:12px;
}

CSS Units

Unit

Description

cm

centimeters

mm

millimeters

in

inches (1in = 96px = 2.54cm)

px *

pixels (1px = 1/96th of 1in)

pt

points (1pt = 1/72 of 1in)

pc

picas (1pc = 12 pt)

em

Relative to the font-size of the element (2em means 2 times the size of the current font)


* Pixels (px) are relative to the viewing device

CSS Selectors:

  • Selectors are used to declare which of the markup elements a style applies to
  • The declarations that appear in the block that follows the selector may be applied to all elements of a specific type, or only those elements that match a certain attribute
  • Each declaration consists of a property and a value
  • Selectors are one of the most important aspects of CSS as they are used to select elements on a web page so that they can be styled. 
You can define selectors in various ways.
  • Element Type Selector
  • Id Selectors
  • Class Selectors
  • Descendant Selectors
  • Child Selectors
  • Adjacent Sibling Selectors
  • Grouping Selectors
  • CSS Selectors

Rule cascading

The cascading rules define which elements take precedence over others.
  • Sort by Importance
  • Sort by weight
  • Sort by Specificity
  • Sort by Order
1. Sort by Importance
  • an ID will win out over a class
  • a class will win out over a tag
2.  Sort by weight
  • Author: Style Sheet - Inline within the body of the web page
  • Author: Style Sheet - Embedded in the head of the web page
  • Author: Style Sheet – Linked
  • User: Style Sheet
  • Default: Browser
3. Sort by Specificity
  • #content  p em{ color: #foo;}
  • #content p{color: #f00;}
  • #content{color: #333;}
4. Sort by Order
  • If two rules have the same properties, specificy and values the one that appears later in the css will be the one that the browser uses 

Inheritance

  • Some CSS properties by default inherit values set on the current element's parent element
  • For example, if you set a color and font-family on an element, every element inside it will also be styled with that color and font, unless you've applied different color and font values directly to them.

Example:

<!DOCTYPE html>
<html>
<head>
<style>
body
color: blue;
font-family: Arial;
}
h1
color: Yellow; 
}
p
{
text-align:justify;
font-size:20px;
}
b
{
color:red;
}
    </style>
</head>
<body>
<h1>Inheritance Example</h1>
<p>Some CSS properties by default <b>inherit</b> values set on the current element's parent element. For example, if you set a color and font-family  on an element, every element inside it will also be styled with that color and font, unless you've applied different color and font values directly to them. </p>
</body>
</html>

Background Properties


Property Name

Value

background-color

red, blue

background-image

url("gradient_bg.png")

background-repeat

repeat| repeat-x | repeat-y  | no-repeat

bacground-attachment

scroll | fixed

background-position

left top | left center | left bottom | right top

right center | right bottom | center top |

center center | center bottom

background-size

Specify the size of a background-image with "auto" and in pixels

background-clip 

defines how far the background (color or image) should extend within an element

background-origin

padding-box | border-box | content-box | initial | inherit

 

Example:

<!DOCTYPE html>
<html>
<head>
<title>Background Properties</title>
<style>
p{
font-size:30px;
text-align:center;
color:yellow;
}
body 
{
  border: 2px solid black;
  padding: 25px;
  background-color:brown;
  background-image: url(images/bgimg3.jpg);
  background-repeat:no-repeat;
  background-position:right top ;
  bacground-attachment: fixed;
  background-size:100px 100px;
}
</style>
</head>
<body>
<p>This is a heading</p>
</body>
</html> 

Border Images

  • The border-image property allows you to specify an image to be used as the border around an element.
  • The property has three parts:
  • The image to use as the border
  • Where to slice the image
  • Define whether the middle sections should be repeated or stretched

Example:

<!DOCTYPE html>
<html>
<head>
<title>Descendant Selectors</title>
<style>
#borderimg
{
border: 30px solid transparent;
padding: 25px;
border-image: url(images/border3.jpg);
border-image-repeat: round;
border-image-slice: 30;
border-image-width: 10px;
}
</style>
</head>
<body>
<p id="borderimg">This is a heading</p>
</body>
</html> 

Colors

Different ways of representing color in html is as follows:
Color Name
Example: color:red;

Hex Code
#RRGGBB
Example: color:#FF0000;

Decimal Code
(R,G,B)
Example:color:rgb(255,0,0);

Shadows Properties


Property

Description

box-shadow

Adds one or more shadows to an element

text-shadow

Adds one or more shadows to a text



Text Shadow Example:

<!DOCTYPE html>
<html>
<head>
<style>
h1 
{
color: white;
text-shadow: 2px 2px 4px #000000;
}
</style>
</head>
<body>
<h1>Text-shadow effect!</h1>
</body>
</html>

Box Shadow Example:


<!DOCTYPE html>
<html>
<head>
<style> 
div {
  width: 300px;
  height: 100px;
  padding: 15px;
  background-color: yellow;
  box-shadow: 10px 10px;
}
</style>
</head>
<body>
<h1>The box-shadow Property</h1>
<div>This is a div element with a box-shadow</div>
</body>
</html>

Text Transformations

  • 2D Transformation
  • 3D Transformation

2D Transformation

  • 2D Transforms give us the ability to perform basic manipulations on elements in space
  • A transformation modify an element by its shape, size and position. It transforms the elements along the X-axis and Y-axis.
  • There are several types of transformation which are listed below:
    • translate(), translateX(), traslateY()
    • rotate()
    • scale(), scaleX(), scaleY()
    • skew(), skewX(), skewY()
    • matrix()

Function

Description

translate(tx,ty)

Moves the element by the given amount along the X and Y-axis.

translateX(tx)

Moves the the element by the given amount along the X-axis.

translateY(ty)

Moves the the element by the given amount along the Y-axis.

rotate(a)

Rotates the element by the specified angle around the origin of the element, as defined by the transform-origin property.

scale(sx,sy)

Scale the width and height of the element up or down by the given amount. The function scale(1,1) has no effect.

scaleX(sx)

Scale the width of the element up or down by the given amount.

scaleY(sy)

Scale the height of the element up or down by the given amount.

skew(ax,ay)

Skews the element by the given angle along the X and Y-axis.

skewX(ax)

Skews the element by the given angle along the X-axis.

skewY(ay)

Skews the element by the given angle along the Y-axis.

matrix(n,n,n,n,n,n)

Specifies a 2D transformation in the form of a transformation matrix comprised of the six values.


Example:

<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
background-color: pink;
border: 1px solid black;
}
div#myDiv {
transform: rotate(20deg);
}
</style>
</head>
<body>
<div>
2d Transforms Example
</div>
<div id = "myDiv">
2d Transforms Example      
</div>
</body>
</html>

3D Transformation

Function

Description

translate3d(tx,ty,tz)

Moves the element by the given amount along the X, Y & Z-axis.

translateX(tx)

Moves the element by the given amount along the X-axis.

translateY(ty)

Moves the element by the given amount along the Y-axis.

translateZ(tz)

Moves the element by the given amount along the Z-axis.

rotate3d(x,y,z, a)

Rotates the element in 3D space by the angle specified in the last parameter, around the [x,y,z] direction vector.

rotateX(a)

Rotates the element by the given angle around the X-axis.

rotateY(a)

Rotates the element by the given angle around the Y-axis.

rotateZ(a)

Rotates the element by the given angle around the Z-axis.

scale3d(sx,sy,sz)

Scales the element by the given amount along the X, Y and Z-axis. The function scale3d(1,1,1) has no effect.

scaleX(sx)

Scales the element along the X-axis.

scaleY(sy)

Scales the element along the Y-axis.

scaleZ(sz)

Scales the element along the Z-axis.

matrix(n,n,n,n,n,n, n,n,n,n,n,n,n,n,n,n)

Specifies a 3D transformation in the form of a 4×4 transformation matrix of 16 values.

perspective(length)

Defines a perspective view for a 3D transformed element. In general, as the value of this function increases, the element will appear further away from the viewer.


Text Transitions


Property

Description

transition

A shorthand property for setting all the four individual transition properties in a single declaration.

transition-delay

Specifies when the transition will start.

transition-duration

Specifies the number of seconds or milliseconds a transition animation should take to complete.

transition-property

Specifies the names of the CSS properties to which a transition effect should be applied.

transition-timing-function

Specifies how the intermediate values of the CSS properties being affected by a transition will be calculated.


Animations

  • An animation lets an element gradually change from one style to another.
  • You can change as many CSS properties you want, as many times you want.
  • To use CSS animation, you must first specify some keyframes for the animation.
  • Keyframes hold what styles the element will have at certain times.

Components:

  • @keyframe animation-name
    • When you specify CSS styles inside the @keyframes rule, the animation will gradually change from the current style to the new style at certain times.
  • animation-name
    • Defines the name of the animation specified in the @keyframe
  • animation-duration
    • defines how long time an animation should take to complete
    • If the animation-duration property is not specified, no animation will occur, because the default value is 0s

Example:(format-1)

<!DOCTYPE html>
<html>
<head>
<title>Animation Example</title>
<style>
h1,h2
{
text-align:center;
}
@keyframes example 
{
from {font-size: 20px;}
to {font-size:40px;}
}
h1
{
animation-name:example;
animation-duration: 4s;
}
</style>
</head>
<body>
<h1>K.RAMAKRISHNAN COLLEGE OF TECHNOLOGY</h1>
<h2>SAMAYAPURAM, TRICHY</h2>
<hr>
</body>
</html>

Example:(format-2)

<!DOCTYPE html>
<html>
<head>
<style> 
div 
{
width: 100px;
height: 100px;
background-color: red;
color: yellow;
position: relative;
animation-name: example;
animation-duration: 4s;
animation-delay: -2s;
}

@keyframes example 
{
  0%   {background-color:red; left:0px; top:0px;}
  25%  {background-color:yellow; left:200px; top:0px;}
  50%  {background-color:blue; left:200px; top:200px;}
  75%  {background-color:green; left:0px; top:200px;}
  100% {background-color:red; left:0px; top:0px;}
}
</style>
</head>
<body>
<h1>Animation Example</h1>
<div>Welcome to CSS Animation</div>
</body>
</html>

THANK YOU