SlideShare a Scribd company logo
1
Hands on
ADVANCED
CASCADING
STYLE SHEETS
(CSS)
2
ID & CLASS SELECTORS
• ID Selector:
 The id selector is used to specify a style for a single, unique element.
 The id selector uses the id attribute of the HTML element, and is defined
with a "#".
 The style rule below will be applied to the element with id="para1":
• Class Selector:
 The class selector is used to specify a style for a group of elements. Unlike
the id selector, the class selector is most often used on several elements.
 This allows you to set a particular style for many HTML elements with the
same class.
 The class selector uses the HTML class attribute, and is defined with a dot
"."
.center {text-align:center;}
It will be used as..
p.center {text-
align:center;}
3
• Example:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
#para1
{
text-align:center;
color:red;
}
</style>
</head>
<body>
<p id="para1">Hello World!</p>
<p>This paragraph is not affected by the style.</p>
</body>
</html>
4
GROUPING SELECTORS
 In style sheets there are often elements with the same style. To avod
the code repeating, we can group them.
 Here is an example to change the size of an image using CSS.
CSS DIMENSIONS
img.normal
{ height:auto; }
img.big { height:40%; }
img.small { height:10%; }
<body>
<img class="normal" src="logocss.gif" width="95" height="84"
/><br />
<img class="big" src="logocss.gif" width="95" height="84"
/><br />
<img class="small" src="logocss.gif" width="95" height="84" />
</body>
CSS
code
using
classes
5
CSS DISPLAY AND VISIBILITY
 The display property specifies if/how an element is displayed. (none,
block)
Hiding an element can be done by setting the display property to "none"
 The visibility property specifies if an element should be visible or
hidden.
Hiding of an element can also be done by setting visibility property to
"hidden"
 Syntax:
6
CSS FLOAT
 With CSS float, an element can be pushed to the left or right, allowing
other elements to wrap around it.
 Float is very often used for images, but it is also useful when working
with layouts.
 Elements are floated horizontally, this means that an element can
only be floated left or right, not up or down.
 If an image is floated to the right, a following text flows around it, to
the left
 Here is example code to float multiple images on a web page.
<style
type="text/css">
.thumbnail
{
float:left;
width:110px;
height:90px;
margin:5px;
}
</style>
<body>
<h3>Image Gallery</h3>
<img class="thumbnail" src="klematis_small.jpg" width="107"
height="90">
<img class="thumbnail" src="klematis2_small.jpg" width="107"
height="80">
<img class="thumbnail" src="klematis3_small.jpg" width="116"
height="90">
<img class="thumbnail" src="klematis4_small.jpg" width="120"
height="90">
<img class="thumbnail" src="klematis_small.jpg" width="107"
height="90">
7
POSITIONING ELEMENTS
 The CSS positioning properties allow you to position an element.
 It can also place an element behind another, and specify what should
happen when an element's content is too big.
 Elements can be positioned using the top, bottom, left, and right
properties.
 However, these properties will not work unless the position property is
set first.
They also work differently depending on the positioning method.
 There are four different positioning methods.
 Static Positioning:
HTML elements are positioned static by default.
A static positioned element is always positioned according to the normal flow of
the page.
Static positioned elements are not affected by the top, bottom, left, and right
properties.
 Fixed Positioning
An element with fixed position is positioned relative to the browser window.
It will not move even if the window is scrolled.
Fixed positioned elements can overlap other elements.
8
 Relative Positioning
A relative positioned element is positioned relative to its normal position.
The content of relatively positioned elements can be moved and overlap
other elements,
but the reserved space for the element is still preserved in the normal flow.
Relatively positioned elements are often used as container blocks for
absolutely positioned elements.
 Absolute Positioning
An absolute position element is positioned relative to the first parent
element that has a position other than static. If no such element is found, the
containing block is <html>:
Absolutely positioned elements are removed from the normal flow. The
document and other elements behave like the absolutely positioned element
does not exist.
Asma Sajid ; College of Computer Science & Information Studies, GCUF 9
All CSS Positioning Properties
10
ADDING EFFECTS TO IMAGES (1)
• Transparent Image Effect
 The CSS3 property for transparency is opacity.
 We can set value for opacity.
 The opacity property can take a value from 0.0 - 1.0. A lower value
makes the element more transparent.
IE9, Firefox, Chrome, Opera, and Safari use the property opacity for
transparency.
 IE8 and earlier use filter:alpha(opacity=x).
The x can take a value from 0 - 100. A lower value makes the element more
transparent.
11
ADDING EFFECTS TO IMAGES (2)
• Hover Image Effect
 The first CSS block will be similar to the code in transparency example.
 In addition, we need to added what should happen when a user hover
over one of the images.
 In this case we want the image to NOT be transparent when the user
hover over it.
 The CSS for this is: opacity=1. And IE8 and earlier:
filter:alpha(opacity=100).
When the mouse pointer moves away from the image, the image will be
transparent again.
• Syntax:
12
CREATING IMAGE SPRITES
• Image Sprites
 An image sprite is a collection of images put into a single image.
 A web page with many images can take a long time to load and generates multiple
server requests.
 Using image sprites will reduce the number of server requests and save bandwidth.
 Instead of using three separate images, we use single image. (a.jpg)
 following example the CSS specifies which part of the “a.jpg" image to show:
 SYNTAX:
 <img class="home" src="img_trans.gif" /> - Only defines a small transparent image because the
src attribute cannot be empty. The displayed image will be the background image we specify in
CSS.
 width:46px;height:44px; - Defines the portion of the image we want to use
 background:url(img_navsprites.gif) 0 0; - Defines the background image and its position (left
0px, top 0px)
13
EXAMPLE- STRIPES
• Navigation List
 We will use an HTML list, because it can be a link and also supports a
background image.
 Explanation;
#navlist{position:relative;} - position is set to relative to allow absolute positioning
inside it
#navlist li{margin:0;padding:0;list-style:none;position:absolute;top:0;} - margin and
padding is set to 0, list-style is removed, and all list items are absolute positioned.
#navlist li, #navlist a{height:44px;display:block;} - the height of all the images are
44px
14
• Positioning
 Now start to position and style for each specific part:
#home{left:0px;width:46px;} - Positioned all the way to the left, and
the width of the image is 46px
#home{background:url(img_navsprites.gif) 0 0;} - Defines the
background image and its position (left 0px, top 0px)
#prev{left:63px;width:43px;} - Positioned 63px to the right (#home
width 46px + some extra space between items), and the width is
43px.
#prev{background:url('img_navsprites.gif') -47px 0;} - Defines the
background image 47px to the right (#home width 46px + 1px line
divider)
#next{left:129px;width:43px;}- Positioned 129px to the right (start
of #prev is 63px + #prev width 43px + extra space), and the width is
43px.
#next{background:url('img_navsprites.gif') no-repeat -91px 0;} -
Defines the background image 91px to the right (#home width 46px
+ 1px line divider + #prev width 43px + 1px line divider )
15
• Adding Hover Effect.. ?
 We only add three lines of code to add the hover effect:
Explanation
 Since the list item contains a link, we can use the :hover pseudo-class
 #home a:hover{background: transparent
url(img_navsprites_hover.gif) 0 -45px;}
For all three hover images we specify the same background position, only
45px further down

More Related Content

Similar to Lecture 5 & 6 Advance CSS.pptx for web (20)

PPTX
CSS_Dibbo
Sayanton Vhaduri
 
PPTX
Css3
Anjan Banda
 
PPTX
CSS 101
Bramwell Su
 
PPTX
Cascading Style Sheets CSS
Asif Shahzad
 
PPT
gdg_workshop 4 on web development HTML & CSS
SaniyaKhan484230
 
PPTX
css3.pptx
ThiyaguPappu
 
DOC
Class 2 handout css exercises (2)
Erin M. Kidwell
 
PDF
DotNetNuke World CSS3
gravityworksdd
 
PPTX
MTA managing the graphical interface by using css
Dhairya Joshi
 
PDF
CSS3 Refresher
Ivano Malavolta
 
PPT
Html 5 and CSS - Image Element
Kempy7000
 
DOC
Art of css
Raphael Wanjiku
 
DOCX
Css Introduction
SathyaseelanK1
 
PPT
Ict 8 css
Christian Reglos
 
PPT
CSS - Basics
Shubham_Saurabh
 
PPTX
CSS3 basics for beginners - Imrokraft
imrokraft
 
PPTX
HTML and CSS part 3
Julie Iskander
 
PPT
CSS Basics
WordPress Memphis
 
PDF
Organize Your Website With Advanced CSS Tricks
Andolasoft Inc
 
CSS_Dibbo
Sayanton Vhaduri
 
CSS 101
Bramwell Su
 
Cascading Style Sheets CSS
Asif Shahzad
 
gdg_workshop 4 on web development HTML & CSS
SaniyaKhan484230
 
css3.pptx
ThiyaguPappu
 
Class 2 handout css exercises (2)
Erin M. Kidwell
 
DotNetNuke World CSS3
gravityworksdd
 
MTA managing the graphical interface by using css
Dhairya Joshi
 
CSS3 Refresher
Ivano Malavolta
 
Html 5 and CSS - Image Element
Kempy7000
 
Art of css
Raphael Wanjiku
 
Css Introduction
SathyaseelanK1
 
Ict 8 css
Christian Reglos
 
CSS - Basics
Shubham_Saurabh
 
CSS3 basics for beginners - Imrokraft
imrokraft
 
HTML and CSS part 3
Julie Iskander
 
CSS Basics
WordPress Memphis
 
Organize Your Website With Advanced CSS Tricks
Andolasoft Inc
 

More from ZahraWaheed9 (15)

PPT
PHP-04-Forms PHP-04-Forms PHP-04-Forms PHP-04-Forms
ZahraWaheed9
 
PPT
Chapter 5 SE Chapter 5 SE.pptChapter 5 SE.ppt
ZahraWaheed9
 
PPTX
Ch 14_Web Mining.pptxCh 14_Web Mining.pptx
ZahraWaheed9
 
PPTX
Open URL in Chrome Browser from Python.pptx
ZahraWaheed9
 
PPT
php introduction to the basic student web
ZahraWaheed9
 
PPTX
ch 3 of C# programming in advanced programming
ZahraWaheed9
 
PPTX
Responsive Web Designing for web development
ZahraWaheed9
 
PPTX
Color Theory for web development class for students to understand good websites
ZahraWaheed9
 
PPT
C# wrokig based topics for students in advanced programming
ZahraWaheed9
 
PPT
CSharp POWERPOINT SLIDES C# VISUAL PROGRAMMING
ZahraWaheed9
 
PPT
visual programming GDI presentation powerpoint
ZahraWaheed9
 
PPT
Visual programming Chapter 3: GUI (Graphical User Interface)
ZahraWaheed9
 
PPTX
Review Presentation on develeopment of automated quality
ZahraWaheed9
 
PPTX
Cross-Modal Scene Understanding presntation
ZahraWaheed9
 
PPTX
Web Minnig and text mining presentation
ZahraWaheed9
 
PHP-04-Forms PHP-04-Forms PHP-04-Forms PHP-04-Forms
ZahraWaheed9
 
Chapter 5 SE Chapter 5 SE.pptChapter 5 SE.ppt
ZahraWaheed9
 
Ch 14_Web Mining.pptxCh 14_Web Mining.pptx
ZahraWaheed9
 
Open URL in Chrome Browser from Python.pptx
ZahraWaheed9
 
php introduction to the basic student web
ZahraWaheed9
 
ch 3 of C# programming in advanced programming
ZahraWaheed9
 
Responsive Web Designing for web development
ZahraWaheed9
 
Color Theory for web development class for students to understand good websites
ZahraWaheed9
 
C# wrokig based topics for students in advanced programming
ZahraWaheed9
 
CSharp POWERPOINT SLIDES C# VISUAL PROGRAMMING
ZahraWaheed9
 
visual programming GDI presentation powerpoint
ZahraWaheed9
 
Visual programming Chapter 3: GUI (Graphical User Interface)
ZahraWaheed9
 
Review Presentation on develeopment of automated quality
ZahraWaheed9
 
Cross-Modal Scene Understanding presntation
ZahraWaheed9
 
Web Minnig and text mining presentation
ZahraWaheed9
 
Ad

Recently uploaded (20)

PDF
TLE 8 QUARTER 1 MODULE WEEK 1 MATATAG CURRICULUM
denniseraya1997
 
PPTX
PLANNING A HOSPITAL AND NURSING UNIT.pptx
PRADEEP ABOTHU
 
PDF
AI-assisted IP-Design lecture from the MIPLM 2025
MIPLM
 
PDF
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
PPTX
The Gift of the Magi by O Henry-A Story of True Love, Sacrifice, and Selfless...
Beena E S
 
PPTX
How to Manage Expiry Date in Odoo 18 Inventory
Celine George
 
PPTX
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
PPTX
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
PPTX
SD_GMRC5_Session 6AB_Dulog Pedagohikal at Pagtataya (1).pptx
NickeyArguelles
 
PDF
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
 
PPTX
Light Reflection and Refraction- Activities - Class X Science
SONU ACADEMY
 
PDF
Indian National movement PPT by Simanchala Sarab, Covering The INC(Formation,...
Simanchala Sarab, BABed(ITEP Secondary stage) in History student at GNDU Amritsar
 
PPTX
Iván Bornacelly - Presentation of the report - Empowering the workforce in th...
EduSkills OECD
 
PPTX
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
PPTX
Life and Career Skills Lesson 2.pptxProtective and Risk Factors of Late Adole...
ryangabrielcatalon40
 
PPTX
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
 
PDF
CAD25 Gbadago and Fafa Presentation Revised-Aston Business School, UK.pdf
Kweku Zurek
 
PPTX
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
 
PPTX
Different types of inheritance in odoo 18
Celine George
 
PPTX
Introduction to Indian Writing in English
Trushali Dodiya
 
TLE 8 QUARTER 1 MODULE WEEK 1 MATATAG CURRICULUM
denniseraya1997
 
PLANNING A HOSPITAL AND NURSING UNIT.pptx
PRADEEP ABOTHU
 
AI-assisted IP-Design lecture from the MIPLM 2025
MIPLM
 
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
The Gift of the Magi by O Henry-A Story of True Love, Sacrifice, and Selfless...
Beena E S
 
How to Manage Expiry Date in Odoo 18 Inventory
Celine George
 
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
SD_GMRC5_Session 6AB_Dulog Pedagohikal at Pagtataya (1).pptx
NickeyArguelles
 
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
 
Light Reflection and Refraction- Activities - Class X Science
SONU ACADEMY
 
Indian National movement PPT by Simanchala Sarab, Covering The INC(Formation,...
Simanchala Sarab, BABed(ITEP Secondary stage) in History student at GNDU Amritsar
 
Iván Bornacelly - Presentation of the report - Empowering the workforce in th...
EduSkills OECD
 
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
Life and Career Skills Lesson 2.pptxProtective and Risk Factors of Late Adole...
ryangabrielcatalon40
 
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
 
CAD25 Gbadago and Fafa Presentation Revised-Aston Business School, UK.pdf
Kweku Zurek
 
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
 
Different types of inheritance in odoo 18
Celine George
 
Introduction to Indian Writing in English
Trushali Dodiya
 
Ad

Lecture 5 & 6 Advance CSS.pptx for web

  • 2. 2 ID & CLASS SELECTORS • ID Selector:  The id selector is used to specify a style for a single, unique element.  The id selector uses the id attribute of the HTML element, and is defined with a "#".  The style rule below will be applied to the element with id="para1": • Class Selector:  The class selector is used to specify a style for a group of elements. Unlike the id selector, the class selector is most often used on several elements.  This allows you to set a particular style for many HTML elements with the same class.  The class selector uses the HTML class attribute, and is defined with a dot "." .center {text-align:center;} It will be used as.. p.center {text- align:center;}
  • 3. 3 • Example: <!DOCTYPE html> <html> <head> <style type="text/css"> #para1 { text-align:center; color:red; } </style> </head> <body> <p id="para1">Hello World!</p> <p>This paragraph is not affected by the style.</p> </body> </html>
  • 4. 4 GROUPING SELECTORS  In style sheets there are often elements with the same style. To avod the code repeating, we can group them.  Here is an example to change the size of an image using CSS. CSS DIMENSIONS img.normal { height:auto; } img.big { height:40%; } img.small { height:10%; } <body> <img class="normal" src="logocss.gif" width="95" height="84" /><br /> <img class="big" src="logocss.gif" width="95" height="84" /><br /> <img class="small" src="logocss.gif" width="95" height="84" /> </body> CSS code using classes
  • 5. 5 CSS DISPLAY AND VISIBILITY  The display property specifies if/how an element is displayed. (none, block) Hiding an element can be done by setting the display property to "none"  The visibility property specifies if an element should be visible or hidden. Hiding of an element can also be done by setting visibility property to "hidden"  Syntax:
  • 6. 6 CSS FLOAT  With CSS float, an element can be pushed to the left or right, allowing other elements to wrap around it.  Float is very often used for images, but it is also useful when working with layouts.  Elements are floated horizontally, this means that an element can only be floated left or right, not up or down.  If an image is floated to the right, a following text flows around it, to the left  Here is example code to float multiple images on a web page. <style type="text/css"> .thumbnail { float:left; width:110px; height:90px; margin:5px; } </style> <body> <h3>Image Gallery</h3> <img class="thumbnail" src="klematis_small.jpg" width="107" height="90"> <img class="thumbnail" src="klematis2_small.jpg" width="107" height="80"> <img class="thumbnail" src="klematis3_small.jpg" width="116" height="90"> <img class="thumbnail" src="klematis4_small.jpg" width="120" height="90"> <img class="thumbnail" src="klematis_small.jpg" width="107" height="90">
  • 7. 7 POSITIONING ELEMENTS  The CSS positioning properties allow you to position an element.  It can also place an element behind another, and specify what should happen when an element's content is too big.  Elements can be positioned using the top, bottom, left, and right properties.  However, these properties will not work unless the position property is set first. They also work differently depending on the positioning method.  There are four different positioning methods.  Static Positioning: HTML elements are positioned static by default. A static positioned element is always positioned according to the normal flow of the page. Static positioned elements are not affected by the top, bottom, left, and right properties.  Fixed Positioning An element with fixed position is positioned relative to the browser window. It will not move even if the window is scrolled. Fixed positioned elements can overlap other elements.
  • 8. 8  Relative Positioning A relative positioned element is positioned relative to its normal position. The content of relatively positioned elements can be moved and overlap other elements, but the reserved space for the element is still preserved in the normal flow. Relatively positioned elements are often used as container blocks for absolutely positioned elements.  Absolute Positioning An absolute position element is positioned relative to the first parent element that has a position other than static. If no such element is found, the containing block is <html>: Absolutely positioned elements are removed from the normal flow. The document and other elements behave like the absolutely positioned element does not exist.
  • 9. Asma Sajid ; College of Computer Science & Information Studies, GCUF 9 All CSS Positioning Properties
  • 10. 10 ADDING EFFECTS TO IMAGES (1) • Transparent Image Effect  The CSS3 property for transparency is opacity.  We can set value for opacity.  The opacity property can take a value from 0.0 - 1.0. A lower value makes the element more transparent. IE9, Firefox, Chrome, Opera, and Safari use the property opacity for transparency.  IE8 and earlier use filter:alpha(opacity=x). The x can take a value from 0 - 100. A lower value makes the element more transparent.
  • 11. 11 ADDING EFFECTS TO IMAGES (2) • Hover Image Effect  The first CSS block will be similar to the code in transparency example.  In addition, we need to added what should happen when a user hover over one of the images.  In this case we want the image to NOT be transparent when the user hover over it.  The CSS for this is: opacity=1. And IE8 and earlier: filter:alpha(opacity=100). When the mouse pointer moves away from the image, the image will be transparent again. • Syntax:
  • 12. 12 CREATING IMAGE SPRITES • Image Sprites  An image sprite is a collection of images put into a single image.  A web page with many images can take a long time to load and generates multiple server requests.  Using image sprites will reduce the number of server requests and save bandwidth.  Instead of using three separate images, we use single image. (a.jpg)  following example the CSS specifies which part of the “a.jpg" image to show:  SYNTAX:  <img class="home" src="img_trans.gif" /> - Only defines a small transparent image because the src attribute cannot be empty. The displayed image will be the background image we specify in CSS.  width:46px;height:44px; - Defines the portion of the image we want to use  background:url(img_navsprites.gif) 0 0; - Defines the background image and its position (left 0px, top 0px)
  • 13. 13 EXAMPLE- STRIPES • Navigation List  We will use an HTML list, because it can be a link and also supports a background image.  Explanation; #navlist{position:relative;} - position is set to relative to allow absolute positioning inside it #navlist li{margin:0;padding:0;list-style:none;position:absolute;top:0;} - margin and padding is set to 0, list-style is removed, and all list items are absolute positioned. #navlist li, #navlist a{height:44px;display:block;} - the height of all the images are 44px
  • 14. 14 • Positioning  Now start to position and style for each specific part: #home{left:0px;width:46px;} - Positioned all the way to the left, and the width of the image is 46px #home{background:url(img_navsprites.gif) 0 0;} - Defines the background image and its position (left 0px, top 0px) #prev{left:63px;width:43px;} - Positioned 63px to the right (#home width 46px + some extra space between items), and the width is 43px. #prev{background:url('img_navsprites.gif') -47px 0;} - Defines the background image 47px to the right (#home width 46px + 1px line divider) #next{left:129px;width:43px;}- Positioned 129px to the right (start of #prev is 63px + #prev width 43px + extra space), and the width is 43px. #next{background:url('img_navsprites.gif') no-repeat -91px 0;} - Defines the background image 91px to the right (#home width 46px + 1px line divider + #prev width 43px + 1px line divider )
  • 15. 15 • Adding Hover Effect.. ?  We only add three lines of code to add the hover effect: Explanation  Since the list item contains a link, we can use the :hover pseudo-class  #home a:hover{background: transparent url(img_navsprites_hover.gif) 0 -45px;} For all three hover images we specify the same background position, only 45px further down