0% found this document useful (0 votes)
53 views

WDD - Cascading Style Sheets

This document provides an introduction and overview of CSS (Cascading Style Sheets). It defines what CSS is, explains why it is used, and describes some of its key advantages over solely using HTML for webpage styling. Specifically, it notes that CSS allows separation of design from content, external style sheet reuse across pages, and superior styling capabilities. The document then covers CSS selectors, different methods of inserting CSS styles (external, internal, inline), and properties for backgrounds, borders, margins and shorthand properties.

Uploaded by

Duminda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

WDD - Cascading Style Sheets

This document provides an introduction and overview of CSS (Cascading Style Sheets). It defines what CSS is, explains why it is used, and describes some of its key advantages over solely using HTML for webpage styling. Specifically, it notes that CSS allows separation of design from content, external style sheet reuse across pages, and superior styling capabilities. The document then covers CSS selectors, different methods of inserting CSS styles (external, internal, inline), and properties for backgrounds, borders, margins and shorthand properties.

Uploaded by

Duminda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

Website Design &

Development
LESSON [5] –CSS - CASCADING STYLE SHEETS

CSS WEBSITE DESIGN & DEVELOPMENT


CSS Introduction
What is CSS?
◦ CSS stands for Cascading Style Sheets
◦ CSS describes how HTML elements are to be displayed on screen, paper, or in other media
◦ CSS saves a lot of work. It can control the layout of multiple web pages all at once
◦ External stylesheets are stored in CSS files

Why Use CSS?


◦ CSS is used to define styles for your web pages, including the design, layout and variations in display for
different devices and screen sizes.

CSS WEBSITE DESIGN & DEVELOPMENT


CSS Solved a Big Problem
◦ HTML was NEVER intended to contain tags for formatting a web page!
◦ HTML was created to describe the content of a web page, like:
◦ <h1>This is a heading</h1>
◦ <p>This is a paragraph.</p>
◦ When tags like <font>, and color attributes were added to the HTML 3.2
specification, it started a nightmare for web developers. Development of large
websites, where fonts and color information were added to every single page,
became a long and expensive process.
◦ To solve this problem, the World Wide Web Consortium (W3C) created CSS.
◦ CSS removed the style formatting from the HTML page!

CSS WEBSITE DESIGN & DEVELOPMENT


Advantages of CSS
◦ CSS saves time − You can write CSS once and then reuse same sheet in multiple
HTML pages. You can define a style for each HTML element and apply it to as many
Web pages as you want.
◦ Pages load faster − If you are using CSS, you do not need to write HTML tag
attributes every time. Just write one CSS rule of a tag and apply it to all the
occurrences of that tag. So less code means faster download times.
◦ Easy maintenance − To make a global change, simply change the style, and all
elements in all the web pages will be updated automatically.
◦ Superior styles to HTML − CSS has a much wider array of attributes than HTML, so
you can give a far better look to your HTML page in comparison to HTML attributes.
◦ Multiple Device Compatibility − Style sheets allow content to be optimized for more
than one type of device. By using the same HTML document, different versions of a
website can be presented for handheld devices such as PDAs and cell phones or for
printing.
◦ Global web standards − Now HTML attributes are being deprecated and it is being
recommended to use CSS. So its a good idea to start using CSS in all the HTML pages
to make them compatible to future browsers.
◦ Offline Browsing − CSS can store web applications locally with the help of an offline
catche. Using of this, we can view offline websites.The cache also ensures faster
loading and better overall performance of the website.
◦ Platform Independence − The Script offer consistent platform independence and can
support latest browsers as well.

CSS WEBSITE DESIGN & DEVELOPMENT


CSS Selectors
◦ CSS selectors are used to "find" (or select) HTML
elements based on their element name, id, class,
attribute, and more.
◦ Type of selector:
◦ Element selector
◦ ID selector
◦ Class selector
◦ Grouping selector

CSS WEBSITE DESIGN & DEVELOPMENT


<html>
<head> <body>
<style>
p{ <h1>Element Selector</h1>
text-align: center; <p>Every paragraph will be affected by the style.</p>
color: red;
} <h1>ID Selector </h1>
#para1 { <p id="para1">Hello World!</p>
text-align: right;
color: green; <h1>Class Selector</h1>
} <h1 class="center">Red and center-aligned heading</h1>
.center { <p class="center">Red and center-aligned paragraph.</p>
text-align: left;
color: blue; <h1>Grouping Selectora</h1>
} <h4>Hello World!</h4>
<h2>Smaller heading!</h2>
h4,h2, p { <p>This is a paragraph.</p>
text-align: center;
color: purple; </body>
} </html>

</style>
</head>
CSS WEBSITE DESIGN & DEVELOPMENT
The id Selector
The id selector uses the id attribute of an HTML element to select a specific element.
The id of an element should be unique within a page, so the id selector is used to select one
unique element!
To select an element with a specific id, write a hash (#) character, followed by the id of the
element.
The style rule below will be applied to the HTML element with id="para1":
#para1 {
text-align: center;
color: red;
}

CSS WEBSITE DESIGN & DEVELOPMENT


The class Selector
The class selector selects elements with a specific class attribute.
To select elements with a specific class, write a period (.) character, followed by the name of
the class.
In the example below, all HTML elements with class="center" will be red and center-aligned:

Example
.center {
text-align: center;
color: red;
}

CSS WEBSITE DESIGN & DEVELOPMENT


The class Selector filtered by element
You can also specify that only specific HTML elements should be affected by a class.
In the example below, only <p> elements with class="center" will be center-aligned:

p.center {
text-align: center;
color: red;
}

CSS WEBSITE DESIGN & DEVELOPMENT


Selecting More than one class
HTML elements can also refer to more than one class.
In the example below, the <p> element will be styled according to
class="center" and to class="large":

<p class="center large">This paragraph refers to two classes.</p>

Class 1= center
Class 2= large

CSS WEBSITE DESIGN & DEVELOPMENT


Three Ways to Insert CSS
External style sheet
Internal style sheet
Inline style

CSS WEBSITE DESIGN & DEVELOPMENT


External style sheet
With an external style sheet, you can change the look of an entire website by
changing just one file!
Each page must include a reference to the external style sheet file inside the
<link> element. The <link> element goes inside the <head> section:

HTML Sheet
Save this as name.htm

CSS sheet
(Save this as mystyle.css)

CSS WEBSITE DESIGN & DEVELOPMENT


Internal Style Sheet
An internal style sheet may be used if one single page has a unique style.
Internal styles are defined within the <style> element, inside the <head>
section of an HTML page:

CSS WEBSITE DESIGN & DEVELOPMENT


Inline Styles
An inline style may be used to apply a unique style for a single element.
To use inline styles, add the style attribute to the relevant element. The style
attribute can contain any CSS property.
The example below shows how to change the color and the left margin of a
<h1> element:

CSS WEBSITE DESIGN & DEVELOPMENT


Cascading Order
What style will be used when there is more than one style specified for an
HTML element?
Generally we can say that all the styles will "cascade" into a new "virtual" style
sheet by the following rules, where number one has the highest priority:
◦ Inline style (inside an HTML element)
◦ External and internal style sheets (in the head section)
◦ Browser default

So, an inline style (inside a specific HTML element) has the highest priority,
which means that it will override a style defined inside the <head> tag, or in an
external style sheet, or a browser default value.

CSS WEBSITE DESIGN & DEVELOPMENT


CSS Backgrounds
CSS background properties:
◦ background-color –
body {
background-color: lightblue;
}
h1 {
background-color: green;
}
◦ background-image -
body {

background-image: url("background-wallpapers-34.jpg");

CSS WEBSITE DESIGN & DEVELOPMENT


CSS Backgrounds
◦ background-repeat –
◦ background-repeat: repeat|repeat-x|repeat-y
body
{
background-repeat: repeat-x;
}
◦ background-position
◦ left top|left center|left bottom|right top|right center|right bottom|center top|center center
center bottom
body
{
background-position: right top;
}

CSS WEBSITE DESIGN & DEVELOPMENT


CSS Borders

CSS WEBSITE DESIGN & DEVELOPMENT


CSS WEBSITE DESIGN & DEVELOPMENT
CSS Margins
Margin - Individual Sides
CSS has properties for specifying the margin
for each side of an element:
•margin-top
•margin-right
•margin-bottom
•margin-left

CSS WEBSITE DESIGN & DEVELOPMENT


All the margin properties can have the following values:
•auto - the browser calculates the margin
•length - specifies a margin in px, pt, cm, etc.
•% - specifies a margin in % of the width of the containing element
•inherit - specifies that the margin should be inherited from the parent element

Tip: Negative values are allowed.


The following example sets different margins for all four sides of a <p> element:

CSS WEBSITE DESIGN & DEVELOPMENT


Margin - Shorthand Property
To shorten the code, it is possible to specify all the margin properties in one
property.
The margin property is a shorthand property for the following individual
margin properties:

CSS WEBSITE DESIGN & DEVELOPMENT


margin-top
margin-right
margin-bottom
margin-left
So, here is how it works:
If the margin property has four values:

CSS WEBSITE DESIGN & DEVELOPMENT


CSS Height and Width

CSS WEBSITE DESIGN & DEVELOPMENT


CSS format
Text Alignment

CSS WEBSITE DESIGN & DEVELOPMENT


Text Decoration

CSS WEBSITE DESIGN & DEVELOPMENT


Text Transformation

CSS WEBSITE DESIGN & DEVELOPMENT


Text Shadow
The following example specifies the position of the horizontal shadow (3px), the
position of the vertical shadow (2px) and the color of the shadow (red):

CSS WEBSITE DESIGN & DEVELOPMENT


Font Icons

➢ We will be using an external


library to display icons.

➢ The link to the external css


library is given using the
href,.

CSS WEBSITE DESIGN & DEVELOPMENT


CSS Links

Styling Links

CSS WEBSITE DESIGN & DEVELOPMENT


Background Color of the link

CSS WEBSITE DESIGN & DEVELOPMENT


Advanced - Link Buttons

CSS WEBSITE DESIGN & DEVELOPMENT


CSS Tooltip
A tooltip is often used to specify extra information about something when the
user moves the mouse pointer over an element:

CSS WEBSITE DESIGN & DEVELOPMENT


CSS Navigation Bar
Having easy-to-use navigation is important for any web site.
With CSS you can transform boring HTML menus into good-looking
navigation bars. Navigation Bar = List of Links

CSS WEBSITE DESIGN & DEVELOPMENT


Vertical Navigation Bar

CSS WEBSITE DESIGN & DEVELOPMENT


Horizontal Navigation Bar

CSS WEBSITE DESIGN & DEVELOPMENT


CSS Forms

CSS WEBSITE DESIGN & DEVELOPMENT


Code continues

CSS WEBSITE DESIGN & DEVELOPMENT


Design the following web page

CSS WEBSITE DESIGN & DEVELOPMENT


Any Question ?

The End..!!

CSS WEBSITE DESIGN & DEVELOPMENT

You might also like