Web Design Lecture Notes Draft
Web Design Lecture Notes Draft
Example:
<!doctype html>
<html>
<head>
<title> Hello </title>
</head>
<body>
<p> TISHK International University </p > <br>
<h1> TISHK International University </h1> <br>
<h2> TISHK International University </h2> <br>
<h3> TISHK International University </h3> <br>
<h4> TISHK International University </h4> <br>
<h5> TISHK International University </h5> <br>
<h6> TISHK International University </h6> <br>
<h7> TISHK International University </h7> <br> <!– no change here
</body>
</html>
Tags ends when we close them, otherwise , it will continue. tags used to be nested inside
each other. Note : Tags in the coming examples will be written inside the body.
<p> text 1<p>
<p> text 2</p>
Or <p>
text 1 text
2</p>
Example:
<table>
<tr>
<th> Name </th> <!-- this is for header , it will be bold -->
<th> Age </th>
<th> Stage </th>
</tr>
<tr>
<td> Ali </td> <!-- this is for data , it will be correspondent to the hd above -->
<td> 20 </td>
<td> Second </td>
</tr>
<tr>
<td> Saly </td> <td> 21 </td>
<td> Third </td>
</tr>
</table>
WEB Links
Syntax:
<a href=“website link"> Text appear in the page </a> Example:
<a href="http://www.tiu.edu.iq">
Click to visit TISHK Website </a>
1- Input Box:
The input box is used to enter data as user name and password as shown in the figure.
Example:
<!doctype html>
<html>
<head>
<title> TIU Page</title>
</head>
<body>
<form action =" " method = " " >
Example
form action =" " method = " " >
Answer : </br> yes
<input type ="radio" name="yesno" value=""> <br> <br>
No
<input type ="radio" name="yesno" value="" > <br> <br>
</form>
4- Check box
<form action =" " method = " " >
Which cities you had visited : </br>
<input type ="checkbox" value="" > Paris <br> <br>
</form>
<input type ="checkbox" value="" > Cairo <br> <br>
</form>
<input type ="checkbox" value=""> Istanbul <br> <br>
5-Number
<form action =" " method = " " >
Exam Mark : </br>
<input type ="number" min="0" max="100"> <br> <br>
</form>
Title =“ The title that will be shown when the mouse is over the object”
Alt=“” the caption that will be shown the “Alternative” text if the image can not be
loaded.
Example:
<img src="baby.jpg" width="200" height="150" title="Baby image">
<img src="babymissed.jpg" width="200" height="150" title="Baby image" alt="baby
image">
Adding Audio
<audio controls>
<source src="Audio.mp3"/>
</audio>
To add autoplay and loop:
<audio controls autoplay loop>
<source src="Audio.mp3"/>
</audio>
Adding Video
Cascading Style Sheets (CSS) is a style sheet language used for describing the presentation
of a document written in a markup language like HTML. CSS is designed to enable the
separation of presentation and content, including layout, colors, and fonts.
CSS is called in the header to define the formatting for each tag as explained in the
example below:
<!doctype html>
<html>
<head>
<title> welcome</title>
</head>
<style> h1
{
color:Red; <!—in this part we defined that each h1 tag will be in red color. Any formatting
related to h1 will be written inside these two brackets.
}
</style>
<body>
<h1> TISHK University</h1> The Sentence TISHK university will appear in red color
</body>
</html>
Ex2:
<!doctype html>
<html>
<head>
<title> My Page</title>
</head>
<style> h1,h2{
Background-color:blue <!-- Here, both h1 and h2 formatting will be changed.>
}
</style>
<body>
<h1> Tishk first Test </h1>
<p> Here is the introduction about university </p>
<h2> Contact page will be here </h2>
<p> Email us at something@tiu </p>
</body>
</html>
In case of :
Body{
Color=red;
}
All the body will be red, however, if we add individual color to <h1> for example it will
overwrite the old one , i.e. the body.
Changing Font
</head> <style> h1{
background-color:blue;
}
p{ color:blue;
font-size: 25px;
font-family:Arial;
}
</style>
<body>
<h1> Tishk first Test </h1>
<p> Here is the introduction about university </p>
<h2> Contact page will be here </h2>
<p> Email us at something@tiu </p>
</body>
</html>
To use the CLASS in more than one tag, use the class without a name.
<!doctype html>
<html>
<head>
<title> CSS lectures</title>
</head>
<style>
.blue {
color: blue;
}
</style>
<body>
<h1 class=blue> Here is the blue header1 </h1> <h2
class=blue> Here is the blue header2 </h2>
<br>
<p class=blue> Here is the blue paragraph </p>
</body>
</html>
Example:
In this example the css file Colors.css will be called by the html file.
CSS FILE
Colors.css p.par1
{
color:blue;
}
p.par2
{
color:red;
}
p.par3
{
color:green;
}
HTML File:
<!doctype html>
<html>
<head>
<title> CSS lectures</title>
<body>
<p class=par1> Here is the normal paragraph </p>
<p class=par2> Here is the normal paragraph </p> <p
class=par3> Here is the normal paragraph </p>
</body>
</html>
Every element we have in HTML . <P> <h1> <h2> .. Etc has Content, padding, border
and Margin to make the design consistent and keep the spaces between elements.
1- Content: The background color which will show the content box.
In CSS file this is tagged as par1 (as shown in color example before) a text will be
written in HTML.
p.par1
{
color:blue;
background-color:yellow;
}
Content
4- Margin : The space between the element and the page. p.par1
{
color:blue; background-color:yellow;
padding: 25px; border-color: red;
border-width: 5px; border-style: solid;
Margin: 60px;
}
JavaScript is the programming language that can be used to program the Web pages.
It is written between <script> tags.
It can be written inside the HTML, but as CSS, creating a separate file for JavaScript
(*.js) and called by HTML is preferred for reusability and ease of coding.
The js file will be created in text editor and saved, for example code.js.
Then it will be called in the HTML file within the head using the following command:
<script src=“code.js”>
</script>
First Example:
In this code the Code.js file will be called in Webpage.html to show a statement. The
function document.write is used as a JavaScript command.
Webpage.html:
<!doctype html>
<html>
<head>
<title> Welcome to Java Script</title>
<script src="Code.js">
</script>
</head>
<body>
<form>
</body>
</html>
Variables in JS
In java script, variables can be a number, string or Boolean. Even if it is not compulsory
to write the command “var” but it is preferred for code understanding. Code.js: ( In
HTML file only calling is required) var x=4; var y=7; var z=x+y; document.write(“The
addition result is ” + z) //+z to show two elements the text and the value.
Example:
var x=4; var y=7;
if (x > y) {
document.write ( "x is greater than y and it is equal to " + x );
} else
{document.write ( "y is equal to or greater than x and it is equal to " + y); }
For Loop Statement Syntax
:
for ( initial value; final value; condition)
{
Repeated Statement(s)
}
Example:
for (var i=1;i<=5;i++)
{
document.write(" This is the repeated statement... ");
}
Syntax :
Functions:
Function are used to reduce the code complexity and to be reused multiple times. The
function is defined and then called. The example below shows “add” function which
receive two numbers and find the summation.
The previous function sends the results directly to the page, however; if it is required to
return the result of the function to the code, the following example is used:
function add(x, y)
{
z=x+y;
return (z);
}
m= add( 7 , 8);
//Webpage.html
<!doctype html><!doctype html>
<html>
<head>
<title> Welcome to Java Script</title>
<script src="Code.js">
</script>
</head>
<body>
<p id="text-1"> TISHK INTERNATIONAL UNIVERSITY </p>
<button onclick="changeStyle()"> Submit </button>
</body>
</html>
//Code.js function
changeStyle()
{
document.getElementById("text-1").style.color="blue";
}
//Webpage.html
<!doctype html><!doctype html>
<html>
<head>
<title> Welcome to Java Script</title>
<script src="Code.js">
</script>
</head>
<body>
<p id="text-1"> Old Text </p>
<button onclick="changeText()"> Submit </button>
</body>
</html>
//Code.js function
changeText()
{
document.getElementById("text-1").innerHTML=" New Text";
}
//Website.html
<!doctype html>
<html>
<head>
<title> Welcome to Java Script</title>
<script src="Code.js">
</script>
</head>
<body>
<p id="text-1"> This text will be copied </p> <br>
<p id="text-2"> This text will be changed to be like the text above </p>
<button onclick="changeText()"> Submit </button>
</body>
</html>
//Code.js function
changeText()
{
var myText=document.getElementById("text-1").innerHTML;
document.getElementById("text-2").innerHTML=myText;
}
Reading Input text contents:
In this example, the input of the user using input text box will be read and copied to the
paragraph.
//Website.html
<!doctype html>
<html>
<head>
<title> Welcome to Java Script</title>
<script src="Code.js">
</script>
</head>
<body>
<p id="text-1"> This text will be copied :</p>
<input type ="text" id="input-1" name=" ">
<p id="text-2"> This text will be changed to user input </p>
<button onclick="changeText()"> Submit </button>
</body>
</html>
Code.js function
changeText()
{
var myText=document.getElementById("input-1"); var
oldtext=myText.value;
Password Validation
In this section, the user input will be checked if it is match the saved password (1234) or
not. If the password is true , the sentence “ Successful Login” will be shown, otherwise,
the sentence “Wrong password” will be shown. Note that if statement is required to check
the validity of the input text.
Website.html
<!doctype html>
<html>
<head>
<title> Welcome to Java Script</title>
<script src="Code.js">
</script>
</head>
<body>
<p> Please Enter The Password :</p>
<input type ="text" id="input-1" name=" ">
<p id="text-1"> The Login result will be shown here </p>
<button onclick="checkPassword()"> Submit </button>
</body>
</html>
Code.js
function checkPassword()
{
var myText=document.getElementById("input-1").value;
if (myText=="1234")
document.getElementById("text-1").innerHTML="Successful Login";
else
document.getElementById("text-1").innerHTML="Wrong Password";
}
//Q: Use the for loop to count the number of login attempts and show it on the page.