Web Design Lecture Notes
Web Design Lecture Notes
(Lecture Notes)
Introduction to: HTML – CSS – Java Script
Prepared by : Dr.Taha Basheer Taha
IT Department / Faculty of sciences
HTML
HTML is stand for Hypertext Markup Language is the standard markup language for
documents designed to be displayed in a web browser. It can be assisted by technologies
such as Cascading Style Sheets (CSS) and scripting languages such as JavaScript. It
relied on tags < > and <between tags there are the Markup Elements.
HTML code can be written using any text editor, however, the compiler is browser that
will be used, as Chrome or Mozilla.
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>
Creating Tables:
The table command <table> is used to create the table. The table is created row after row.
If the table row is a header, then <th> is used, and it is shown as bold. When the row
contains data then <td> tag is used.
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>
Adding Images
Syntax:
<img src=“name.extension" width=“num" height=“num">
<!-- the image should be on same folder if no path was specified-->
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 = " " >
<input type =“text" name=" ">
</form>
</body>
</html>
<!– when input type = password then characters will be shown as asterisk.
2- Submit bottom
<form action =" " method = " " >
<input type ="submit" value=" Submit “ name=“ ”>
</form>
3-Radio Bottom
Syntax:
<input type ="radio" name="yesno" value=""> <br> <br>
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>
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">
Labels to the input box
Syntax:
<label for=" id of the input box "> text to show </label>
<input type ="text" id="id of the input box " name=" ">
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>
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
2- Padding : Padding is the place between the color and text.
p.par1
{
color:blue;
background-color:yellow;
padding: 25px; <!– This is for all sides-->
<!– it can be specified as in image->
}
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.
Code.js:
document.write("This statement is written inside JS file");
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.
IF Conditional Statement
Syntax:
if(condition)
{ Statements to run when the condition is true}
else {in case of the condition is not true}
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 :
var Arrayname= [ elment 1, element 2, …. Element n]
Example:
var users=["Ahmed Saad", "Ali Salim", "Layla Mohammed",];
document.write (users[0]);
//The first user “Ahmed Saad” will be shown
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";
}
Changing text contents
innerHTML is used to set the text inside the element. For the paragraph of the id : text-1
the text is changed from Old Text to New Text after pressing on the button.
//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";
}
//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;
var updateMe=document.getElementById("text-1");
updateMe.innerHTML=oldtext;
}
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.