Lec6 CSS
Lec6 CSS
CSS is a styling language. Using CSS, we can define styles for HTML element. These styles are
applied on HTML elements when we include CSS code in the HTML document. In CSS code we
write style rules for HTML elements. These rules govern the presentation of those elements in
the browser. A CSS rule consists of a selector which is the HTML element on which we want to
apply style and a declaration of style. In style declaration we use the properties of the selector
and apply a specific value to these properties. In previous lecture we have discussed the basic
syntax of CSS rules.
As we discussed, CSS is not a programming language. Rather, it is a styling language. We need
to learn the properties for HTML elements and possible values which can be assigned to that
particular property. In this way we can style the HTML elements. In this lecture, we will learn
properties of some the basics elements of HTML.
2. Text properties:
These properties are used to control the appearance of text. Following are the most common
text related properties
color: specifies the color of the text
• Common values: color name or codes
• Example: P{color : green}
text-align: horizontal alignment of the text
• Common values: Left, right, center or justify
vertical-align:Vertical alignment of the text
• Common values: Sub, super, top, middle, bottom
text-decoration: specifies the whether the text should be underline, over-line, line-through or
blinking
• Common values: be underline, over-line, line-through or blinking
text-transform: text should be lowercase, uppercase or capitalized
• Common values: lowercase, uppercase or capitalized
letter-spacing:Specifies the space between letters
• Common values: usually, value is given in pixels
• Example: H1{letter-spacing:3px}
word-spacing:Specifies the space between word
• Common values: usually, value is given in pixels
• Example: H1{word-spacing:4px}
In following example we use these properties to define style and then, use the style in a HTML
page.
mystyle.css <html>
h1{ <head>
font-family:arial; <title> Text properties</title>
font-size:36px; <link href="mystyle.css" type="text/css"
} rel="stylesheet">
h1.title{ </head>
color:orange; <body>
text-transform:uppercase; <h1 class="title">COMSATS institute of I.T</h1>
text-align:center; <hr size="5" color="lightblue">
letter-spacing:5px; <h1 class="bodytext">introduction:</h1>
} </body>
h1.bodytext{ </html>
color:purple;
text-transform:capitalize;
text-decoration:underline;
font-size:24px;
}
3. Styling links:
Following are the major properties used to style links.
color: Changes the color of the links
background-color: Highlights the link, as if it had been highlighted with a highlighter pen
text-decoration: Underline, strike through, over-line, blink
In CSS, there are some predefined classes to style different states of a link. These classes are
Link: Styles for links in general
Visited:Styles the links which are already visited
Hover:Styles when some on hovering over a link
Active:Styles the links when a links is being clicked
In the following code we have used these properties to style links.
a{
font-family:calibri;
font-size:24px;
text-decoration:none;
font-weight:bold
}
a:link{
color:red;
}
a:visited{
color:yellow;
}
a:hover
{
background-color:gray;
text-decoration:underline;
}
5. Styling tables:
We can control the appearance of tables using CSS. To control the appearance of text in tables,
we can use text and font related properties. Some basics table related properties are given
below
Border related properties are used to control the appearance of border around the table
border-style: control the border style
• Common values: solid, dashed, doted, double etc.
border-color: used to set the color of the border
padding property: is used to set the space between the border of a cell and its contents
padding-left: is used to set the space between left border of a cell and its contents
padding-right: is used to set the space between right border of a cell and its contents
padding-top: is used to set the space between top border of a cell and its contents
padding-bottom:is used to set the space between bottom border of a cell and its contents
Following example shows the use of table related properties.
table{ <html>
border-style:dashed; <head>
border=3px; <title> Text properties</title>
width:300px; <link href="style.css" type="text/css"
} rel="stylesheet">
th{ </head>
font-family:calibri; <body>
background-color:gray; <h1 class="bodytext">Table Style</h1>
} <table>
td{ <tr>
background-color:lightblue; <th>Name</th>
vertical-align:top; <th>Registration No</th>
} </tr>
tr{ <tr>
height:50px;} <td>Bashart</td>
<td>FA09-RCS-001</td>
</tr>
</body>
</html>
In previous lecture we discussed some basic CSS properties. These properties are used to
control the presentation of HTML elements. In this lecture we will discuss the entire process of
designing a page layout.
1.4 Identify key elements for each page:Now that you know what pages will make up the
site, go back to the groups of information and add these onto the relevant pages. There will be
some key items or elements that should appear on each page, such as a logo/branding, primary
navigation, page headings, and a search box. Other information is more likely to appear on only
one page, such as individual product details or terms and conditions. When you are identifying
the key elements of each page, several pages, may contain similar types of information. The
structure of these pages should be very similar.
1.5 Arranging the elements:Once you know what needs to appear on each page, then you
can start to look at page layout, which involves the arrangement of the information on your
pages. Suppose we have decided that a specific page will contain a login form and a registration
form, while header and footer are the common sections for all pages. We can draw these
elements on a paper to design the page layout where we can arrange the elements of the page
at different locations. One of the options is shown in the following figure
1.6 Translating the design into code:Having determined what your page will look like, you
need to translate your designs into code. Usually, we use div tag to declare sections in the web
page, while CSS is used to control/style the presentation of these sections. We have also to
decide; whether the page design will be liquid or fixed. Now days, users access the web
application through multiple devices. These devices differ in size. Liquid designs automatically
fit to the screen while fixed designs remain fixed in width. To define a liquid design we use
percentage values to declare height and width of sections while to define a fixed design we
used absolute values.
The div tag: As we discussed earlier to design a web page we define different sections in the
web page and then style these sections using CSS. The div tag defines a division or section in an
HTML document. Visually, it allows us to make containers that can be formatted. We can
declare a div as given below
<div>……</div>
In the following example we use the div tag to define sections in the web page. We also use the
style tag to style these sections.
<html>
<head>
<title>Using divs</title>
</head>
<body>
<div>
<div style="width:100px;backround-color:gray">This is the first section</div>
<div style="width:100px;backround-color:red">This is the second section</div>
</div>
</body>
</html>
In the following example we translate the design of the page given in the previous section into
the code. First we create the HTML page which contains different sections. Then we write CSS
code to style these sections.
HTML page CSS code
body{
<html> background-color:#CCCCCC;
<head> }
<title> Connection Home Page!</title> #container{
<link href="style.css" rel="stylesheet" height:auto;
type="text/css"> width:80%;
</head> margin-left:10%;
<body> border:2px;
<div id="container"> border-color:550000;
<div id="header"> }
<div id="logo"><imgsrc="images/logo.jpg" #header{
height="116" width="170"></div> width:100%;
</div> height:18%;
<div id="center-content"> background:url(images/header.jpg);
<div class="form-container"> background-repeat:repeat;
<div class="form-heading">User Login </div> background-position:0px 0px;
<form> margin:auto;
<div class="form-row"> }
<label>Your ID</label> #logo{
<input type="text" name="ID"> float:left;
</div> padding:0px;
<div class="form-row"> height:100%;
<label>Your Password</label> width:100%;
<input type="password" name="pass"> }
</div> #center-content{
<div class="form-row"> height:auto;
<label></label> width:100%;
<input class="sub" type="submit" value="Login"> background-color:#CCCCCC;
</div> }
</div> div.form-container
<div class="space"></div> {
<div class="form-container"> margin-left:25%;
<div class="form-heading">User Registration margin-right:25%;
</div> margin-top:10px;
<form> height:auto;
<div class="form-row"> width:auto;
<label>Your Full Name:</label> border:2px;
<input type="text" name="name"> border-style:solid;
</div> }
<div class="form-row"> div.form-heading
<label>Your Email Address:</label> {
<input type="text" name="email"> padding:10px;
</div> height:40px;
<div class="form-row"> font-family:calibri;
<label>Your Password:</label> color:white;
<input type="password" name="password"> font-weight:bold;
</div> font-size:26px;
<div class="form-row"> background-color:550000;
<label>Your Picture:</label> }
<input type="file" name="pic"> div.form-row
</div> {
<div class="form-row"> padding:5px;
<label></label> height:25px;
<input class="sub" type="submit" }
value="Register"> label{
</div> font-family:Calibri;
</div> font-size:12px;
</div> padding:10px;
<div id="footer">© all rights reserved width:200px;
</div> float:left;
</div> font-weight:bold;
</body> }
</html> input{
float:left;
height:25px;
width:250px;
}
input.sub{
float:left;
height:25px;
width:150px;
margin-left:100px;
}
div.space
{
height:10px;
}
#footer
{
margin-top:10px;
color:white;
text-align:center;
height:30px;
width:100%;
background-color:550000;
}