Professional Documents
Culture Documents
IP Lecture - Sildes
IP Lecture - Sildes
SHEETS ORIENTATION
2. Write style rules for how you’d like certain elements to look.
Example
h1 {color: green; }
Declarations
p{
font-size: small;
font-family: sans-serif;
• The link element only requires a start tag <link> and is inserted
in between the <head>…</head> tags of our web page
document.
.thick{ font-size:20px; }
• </head>
• </body> </html>
• For example, to make paragraph text blue always, use the following
rule:
• Rule order
for example:
<style type="text/css">
p { color: red; }
p { color: blue; }
p { color: green; }
</style>
Prepared By Mebiratu B. 4-Feb-22 29
Prepared By Mebiratu B. 4-Feb-22 30
More on CSS
• CSS Comments
• A CSS comment starts with /* and ends with */
CSS Selectors
The CSS element Selector
p{
text-align: center;
color: red;
}
#para1 {
text-align: center;
color: red;
}
Prepared By Mebiratu B. 4-Feb-22 31
• The CSS class Selector
.center {
text-align: center;
color: red;
}
• The CSS Universal Selector
• *{
text-align: center;
color: blue;
}
Prepared By Mebiratu B. 4-Feb-22 32
• The CSS Grouping Selector
h1, h2, p {
text-align: center;
color: red;
}
CSS background-image
body {
background-image: url("paper.gif");
}
Prepared By Mebiratu B. 4-Feb-22 33
CSS Borders
• dotted {border-style: dotted;}
.dashed {border-style: dashed;border-width: 2px; border-color: green;}
CSS Margins
✓ The CSS margin properties are used to create space around elements,
outside of any defined borders.
p{
margin-top: 100px;
margin-bottom: 100px;
margin-right: 150px;
margin-left: 80px;
}
div {
padding-top: 50px;
padding-right: 30px;
padding-bottom: 50px;
padding-left: 80px;
color: red;
background-color: yellow;}
a:visited {
color: green;}
a:hover {
color: hotpink;}
a:active {
color: blue;}
Prepared By Mebiratu B. 4-Feb-22 38
CSS Layout - The position Property
• static
• relative
• fixed
• Absolute
position: static
✓ HTML elements are positioned static by default.
✓ Static positioned elements are not affected by the top, bottom, left, and
right properties.
✓ Is not positioned in any special way; it is always positioned according to
the normal flow of the page:
which means it always stays in the same place even if the page is
scrolled. The top, right, bottom, and left properties are used to
• A fixed element does not leave a gap in the page where it would
position: fixed;
bottom: 0;
right: 0;
width: 300px;
• visible - Default. The overflow is not clipped. The content renders outside
the element's box
• hidden - The overflow is clipped, and the rest of the content will be
invisible
• scroll - The overflow is clipped, and a scrollbar is added to see the rest of
the content
47
What can a JavaScript Do?
• put dynamic text into an HTML page
48
How To
• The HTML <script> tag is used to insert a JavaScript into an HTML
page
<script type=“text/javascript”>
document.write(“Hello World!”)
</script>
49
Scripting
• <script> tag
• Indicate that the text is part of a script
• type attribute
• Specifies the type of file and the scripting language use:
• Value: “text/javascript”
• writeln method of the document object
• Write a line in the document and position the cursor in the
next line
• Does not affect the actual rendering of the HTML document
• What is being written by JavaScript is the set of html
instructions that in turn determine the rendering of the html
document
JavaScript Where To
• There are a flexible given to include JavaScript code anywhere in an HTML
document.
• But there are following most preferred ways to include JavaScript in your
HTML file.
51
• <html>
<head>
<title> First JavaScript page </title></head>
<body>
<h1> First JavaScript Page</h1>
<script type=”text/javascript”>
document.write(“<HR>”);
document.write(“Hello World Wide Web”); //comments goes here
document.write(“<HR>”);
</script>
</body>
• </html>
• The interpreter checks each case against the value of the expression until
a match is found.
• If some of the data that had been entered by the client had been in the
wrong form or was simply missing, the server would have to send all
the data back to the client and request that the form be resubmitted with
correct information.
<script type="text/javascript">
function validateEmail()
{
var emailID = document.myForm.EMail.value;
atpos = emailID.indexOf("@");
return( true );
}
</script>
81
Java Objects
• String
• Date
• Array
• Boolean
• Math
• RegExp
• HTML DOM
82
1 <?xml version = "1.0"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
5 <!-- Fig. 7.8: Addition.html -->
6 <!-- Addition Program -->
7
8
9 <head>
Addition.html
<html xmlns = "http://www.w3.org/1999/xhtml">
(1 of 2)
10 <title>An Addition Program</title>
11
12 <script type = "text/javascript">
13 <!--
14 var firstNumber, // first string entered by user
15 secondNumber, // second string entered by user
16 number1, // first number to add
17 number2, // second number to add
18 sum; // sum of number1 and number2
19
20 // read in first number from user as a string
21 firstNumber =
22 window.prompt( "Enter first integer", "0" );
23
24 // read in second number from user as a string
25 secondNumber =
26 window.prompt( "Enter second integer", "0" );
27
28 // convert numbers from strings to integers
29 number1 = parseInt( firstNumber );
30
31
Addition.html
number2 = parseInt( secondNumber );
32
33 (2 of 2)
// add the numbers
sum = number1 + number2;
34
35 // display the results
36 document.writeln( "<h1>The sum is " + sum + "</h1>" );
37 // -->
38 </script>
39
40 </head>
41 <body>
42 <p>Click Refresh (or Reload) to run the script again</p>
43 </body>
44 </html>
Arithmetic Operators and order of evaluation
JavaScript Arithmetic Algebraic JavaScript
operation operator expression expression
Addition + f+7 f + 7
Subtraction - p–c p - c
Multiplication * bm x-- b * m
y
Division / x / y or or xy x / y
Remainder % r mod s r % s
Fig. 7.12 Arithmetic operators.
Operator(s) Operation(s) Order of evaluation (precedence)
*, / or % Multiplication Evaluated first. If there are several such operations,
Division they are evaluated from left to right.
Modulus
+ or - Addition Evaluated last. If there are several such operations,
Subtraction they are evaluated from left to right.
Fig. 7.13 Precedence of arithmetic operators.
Do NOT confuse relational equality operator “==“ with an assignment operator “=“
Order of Precedence for the Basic Operators