SlideShare a Scribd company logo
Web Engineering
Lecture 05
Introduction to CSS
University of Lahore
Nosheen Qamar
1
CASCADING STYLE SHEET
• This is the language to add presentation styling to HTML documents.
• CSS is a powerful and flexible way to add format to web page for resentation.
• Through CSS it is relatively easy to take simple page of text and images,
formatted to present as fully professional webpage.
• CSS has a simple syntax, consist of selectors, properties and values it together
make a style rules.
• It gives developer find ways to control over how each element of page is
formatted.
• CSS styles can apply on HTML documents through several different ways.
– Create an external CSS file.
– Embed CSS code in HTML document.
2
CSS Syntax
• A style rule is made of three parts:
• Selector: A selector is an HTML tag at which style will be applied. This could be
any tag like <h1> or <table> etc.
• Property: A property is a type of attribute of HTML tag. Put simply, all the HTML
attributes are converted into CSS properties. They could be color or border etc.
• Value: Values are assigned to properties. For example color property can have
value either red or #F1F1F1 etc.
• You can put CSS Style Rule Syntax as follows:
selector { property: value; }
• Example: You can define a table border as follows:
table {
border: 1px solid #C00FDF;
}
3
Applying CSS
• There are three ways through which you apply
CSS on your HTML doc.
 Inline
 Internal
 External
4
Inline CSS
• You can also embed your CSS code in
HTML document.
• Example: <p style=“font-family: monospace;”>
5
INTERNAL CSS
• <style></style> always placed between <head></head> tags.
• Example: <style>
p { line-height: 120%; }
</style>
EXTERNAL CSS FILE
External CSS file will always place between <HEAD></HEAD>
tags.
<link rel=“stylesheet” type=“text/css” href=“main.css” />
SELECTORS
• There are three types of selectors:
 Tag selectors
 ID selectors
 Class selectors
6
Example Tag Selector
<style>
p {
font-family: sans-serif;
font-size: 15pt;
line-height: 150%;
}
</style>
7
Tag
selector
Example Class Selector
<style>
.foo {
font-family: sans-serif;
font-size: 15pt;
line-height: 150%;
}
</style>
<p class=“foo”> Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Pellentesque sit amet lorem ligula. Nam pulvinar
nunc ac magna aliquam quis sodales dui elementum. Fusce a
lacus leo. Maecenas ut dui eu quam condimentum sagittis.
</p>
8
class selector
Example Class Selector
<style>
p.foo {
font-family: sans-serif;
font-size: 15pt;
line-height: 150%;
}
</style>
<body>
<h1 class=“foo”></h1>
<p class=“foo”></p>
</body>
9
class
selector
Example ID Selector
<style>
#p1 {
font-family: sans-serif;
font-size: 15pt;
line-height: 150%;
}
</style>
<p id=“p1”> Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Pellentesque sit amet lorem ligula. Nam pulvinar
nunc ac magna aliquam quis sodales dui elementum. Fusce a
lacus leo. Maecenas ut dui eu quam condimentum sagittis.
</p>
10
ID selector
RULE for ID selector
• There is only be one element in a
document with a particular ID selector.
• ID selector can only be used once in
one element/tag.
11
Descendant Selector
<style>
p a {
font-family: sans-serif;
font-size: 15pt;
line-height: 150%;
}
</style>
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit..
Nam pulvinar nunc ac magna aliquam quis sodales dui nunc
sit elementum. <a href=“page1.html”>Donec eu nisi turpis,</a>
sit amet rutrum leo.
</p>
Click <a href=“page2.html”>here</a>
12
Grouping Selector
• you can apply style to many selectors.
• <style>
h1, p, section {
color: #35c;
font-weight: bold;
letter-spacing: .4em;
}
</style>
13
Grouping Class & ID Selectors
• you can apply style to many selectors.
<style>
#content, #footer, .supplement {
position: absolute;
left: 510px;
width: 200px;
}
</style>
14
PSEUDO SELECTOR
<style>
a:link {
color: #008080;
}
a:hover {
color: #FF0000;
}
</style>
15
COMMENTS IN CSS
<style>
/*
p {
font-family: sans-serif;
font-size: 15pt;
}
*/
</style>
16
CSS UNITS - Sizes
• Relative length measurements:
– px (pixels – size varies depending on screen resolution)
– em (usually the height of a font’s uppercase M)
– ex (usually the height of a font’s lowercase x)
– Percentages (of the font’s default size)
• Absolute-length measurements (units that do not vary in size):
– in (inches)
– cm (centimeters)
– mm (millimeters)
– pt (points; 1 pt = 1/72 in)
– pc (picas; 1 pc = 12 pt)
• Generally 1em = 12pt = 16px = 100%
17
Unit Description Example
%
Defines a measurement as a percentage
relative to another value, typically an
enclosing element.
p {
font-size: 16pt;
line-height: 125%;
}
cm Defines a measurement in centimeters. div {margin-bottom: 2cm;}
em
A relative measurement for height of a font
in em spaces. Because an em unit is
equivalent to the size of a given font, if you
assign a font to 12pt, each “em” unit would
be 12pt; thus 2em = 24pt.
p {
letter spacing: 7em;
}
ex
This value defines a measurement relative to
a font’s x-height. The x-height is determined
by the height of the font’s lowercase letter x.
p {
font-size: 24pt;
line-height: 3ex;
}
in Defines a measurement in inches. p { word-spacing: .15in;}
mm Defines a measure in millimeters. p { word-spacing: 15mm;}
pc
Defines a measurement in picas. A pica is
equivalent to 12 points. Thus, there are 6
picas per inch.
p { font-size: 20pc;}
18
19
Unit Description Example
pt
Defines a measurement in points. A point is
defined as 1/72nd of an inch.
body {font-size: 18pt;}
px Defines a measurement in screen pixels. p {padding: 25px;}
CSS – Colors
• You can specify your color values in various
formats.
20
Format Syntax Example
Hex Code #RRGGBB p {color: #FF0000; }
Short Hex Code #RGB p {color: #6A7;}
RGB % rgb(rrr%, ggg%, bbb%)
p {
color: rgb(50%, 50%, 50%);
}
RGB Absolute rgb(rrr, ggg, bbb)
p {
color: rgb(0, 0, 255);
}
keyword aqua, black etc. p { color: teal;}
CSS Box Model
• A set of rules collectively known as CSS Box Model
describes the rectangular region occupied with
HTML elements.
• The main idea is that every element’s layout is
composed of:
 the actual element’s content area.
 a border around the element.
 a padding between the content and the border (inside the border)
 a margin between the border and other content (outside the border)
21
22
Block-Level Elements
• A block level element in HTML create a
“block” or “box”.
• Browsers typically display the block-level
element with a new line.
• Block level elements may contain inline
elements and other block-level elements.
• The block level elements create “larger”
structure than inline elements.
List of Block-Level Elements
<address>
Contact information
<figcaption> (HTML5)
Figure caption
<ol>
Ordered list
<article>(HTML5)
Article content
<figure>(HTML5)
Groups media content with a
caption
<output>(HTML5)
Form output
<aside>(HTML5)
Aside content
<footer>(HTML5)
Section or page footer
<p>
Paragraph
<audio>(HTML5)
Audio player
<form>
Input form
<pre>
Preformatted text
<blockquote>
Long (“block”) quotation
<h1><h2><h3><h4><h5><h6>
Heading levels 1 - 6
<section>(HTML5)
Section of the page
<canvas>(HTML5)
Drawing canvas
<header>(HTML5)
Section or page header.
<table>
Table.
<dd>
Definition description
<hgroup>(HTML5)
Groups header information
<tfoot>
Table footer
<div>
Document division
<hr>
Horizontal rule (dividing line)
<ul>
Unordered list
<dl>
Definition list
<fieldset>
Field set label
<video>(HTML5)
Video player
Inline Elements
• An Inline element in HTML occupies only
the space bounded by the tags that define
the inline element.
• Generally, inline elements may contain
only data and other inline elements.
• By default, inline elements do not begin
with new line.
The <span> & <div> Tags
• A <span> ... </span> element defines an
“inline” structure, i.e. it simply defines a
stretch of text. Thus it can be used within
a paragraph or table element without
affecting the flow of the text.
• A <div> ... </div> element defines a
“block” structure. Usually the browser will
place line breaks before and after this
element, but otherwise it has no effect
itself.
CSS Font Properties
• You can set following font properties of an
element:
 The font-family property is used to change the
face of a font.
 The font-style property is used to make a font
italic or oblique.
 The font-variant property is used to create a
small-caps effect.
 The font-weight property is used to increase or
decrease how bold or light a font appears.
 The font-size property is used to increase or
decrease the size of a font.
font-family
• <p style="font-family: georgia, garamond,
serif;">
This text is rendered in either georgia,
garamond, or the default serif font
depending on which font you have at your
system. </p>
• Output:
This text is rendered in either georgia,
garamond, or the default serif font
depending on which font you have at your
system.
Generic Font Family
• These are the generic name values for the
font-family property, followed by an example
of each that the browser might select from
the user’s system fonts:
29
Generic font-family Names Example
serif Times New Roman
sans-serif Arial
cursive Zapf-Chancery
fantasy Western
monospace Courier
font-style
• <p style="font-style: italic;">
This text will be rendered in italic style. </p>
• Output:
This text will be rendered in italic style.
• Possible Values:
normal, italic, oblique(more slanted than
normal)
30
font-size
• <p style="font-size: 20pt;">
This font size is 20 pixels.
</p>
• Output:
This font size is 20 points.
• Possible values:
px, small, xx-small, x-small, medium, large,31
font-weight
• <p style="font-weight: bold;">
This font is bold.
</p>
• Output:
This font is bold.
• Possible values:
normal, bold, bolder, lighter, 100, 200, 300,
400, 500, 600, 700, 800, 900 32
font-variant
• <p style="font-variant: small-caps;">
This text will be rendered in small caps.
</p>
• Output:
THIS TEXT WILL BE RENEDERED AS
SMALL CAPS.
• Possible values:
normal, small-caps 33
line-height
• The line-height property is used to set the
vertical distance between the baselines of
adjacent lines of text.
• You can use only this property with block-
level elements.
34
CSS Text Formatting
• You can set following text properties of an
element:
 The color property is used to set the color of a
text.
 The letter-spacing property is used to add or
subtract space between the letters.
 The word-spacing property is used to add or
subtract space between the words.
 The text-indent property is used to indent the
text of a paragraph.
 The text-align property is used to align the text
of a document.
 The text-decoration property is used to
underline, overline and strikethrough text.
 The text-transform property is used to
capitalize text or convert text to uppercase or
lowercase letters.
 The text-shadow property is used to set the
text shadow around a text.
 The white-space property is used to control
the flow and formatting of text.
36
color
• <p style=“color: red;” >
This text will be written in red.
</p>
• Output:
This text will be written in red.
• Possible values:
any color name in any valid format. 37
letter-spacing
• <p style=“letter-spacing: 5px;” >
This text is having space between letters.
</p>
• Output:
T h i s t e x t i s h a v i n g s p a c e
b e t w e e n l e t t e r s.
• Possible values:
38
word-spacing
• <p style=“word-spacing: 5px;” >
This text is having space between words.
</p>
• Output:
This text is having space between
words.
• Possible values:
39
text-indent
• The text-indent property is used to indent
only the first line of text within an element.
• The default value for this property is 0.
• It only applies to block-level elements.
40
text-indent
• <p style=“text-indent: 1cm;” >
This text will have first line indent by 1cm.
and this line will remain at its actual
position.
</p>
• Output:
This text will have first line indent
by 1cm.
and this line will remain at its actual
position. 41
text-decoration
• <p style=“text-decoration: underline;” >
This will be underline.
</p>
• Output:
This will be underline.
• Possible values:
none, underline, overline, line-through,
blink 42
text-transform
• <p style=“text-transform: uppercase;” >
This will be in uppercase.
</p>
• Output:
THIS WILL BE IN UPPERCASE.
• Possible values:
none, capitalize, uppercase, lowercase
43
white-space
• The white-space property is used to specify
whether the blank space between words
both horizontally and vertically is collapsed
to a single character space or is retained
and preserved as is.
• The white space property is used with
block-level elements.
44
white-space
• <p style=“white-space: pre;” >
This text has a line break
and the white-space pre setting tells the
browser.
</p>
• Output:
This text has a line break
and the white-space pre setting tells the
browser.
45
text-shadow
• <p style=“text-shadow: 4px 4px 8px blue;”
>
If your browser supports the css text-
shadow property, this text will have a blue
shadow.
</p>
• Output:
• Possible values:
46

More Related Content

What's hot

Web essentials clients, servers and communication – the internet – basic inte...
Web essentials clients, servers and communication – the internet – basic inte...Web essentials clients, servers and communication – the internet – basic inte...
Web essentials clients, servers and communication – the internet – basic inte...
smitha273566
 
Javascript alert and confrim box
Javascript alert and confrim boxJavascript alert and confrim box
Javascript alert and confrim box
Jesus Obenita Jr.
 
Markup language classification, designing static and dynamic
Markup language classification, designing static and dynamicMarkup language classification, designing static and dynamic
Markup language classification, designing static and dynamic
Ankita Bhalla
 
Avl trees
Avl treesAvl trees
Avl trees
ppreeta
 

What's hot (20)

Data Communication & Computer Networks:Digital Signal Encoding
Data Communication & Computer Networks:Digital Signal EncodingData Communication & Computer Networks:Digital Signal Encoding
Data Communication & Computer Networks:Digital Signal Encoding
 
HTML Block and Inline Elements
HTML Block and Inline ElementsHTML Block and Inline Elements
HTML Block and Inline Elements
 
HTML-5 New Input Types
HTML-5 New Input TypesHTML-5 New Input Types
HTML-5 New Input Types
 
Web forms in ASP.net
Web forms in ASP.netWeb forms in ASP.net
Web forms in ASP.net
 
Web essentials clients, servers and communication – the internet – basic inte...
Web essentials clients, servers and communication – the internet – basic inte...Web essentials clients, servers and communication – the internet – basic inte...
Web essentials clients, servers and communication – the internet – basic inte...
 
Procedures functions structures in VB.Net
Procedures  functions  structures in VB.NetProcedures  functions  structures in VB.Net
Procedures functions structures in VB.Net
 
Javascript alert and confrim box
Javascript alert and confrim boxJavascript alert and confrim box
Javascript alert and confrim box
 
Box Model
Box ModelBox Model
Box Model
 
Std 12 Computer Chapter 2 Cascading Style Sheet and Javascript (Part-2)
Std 12 Computer Chapter 2 Cascading Style Sheet and Javascript (Part-2)Std 12 Computer Chapter 2 Cascading Style Sheet and Javascript (Part-2)
Std 12 Computer Chapter 2 Cascading Style Sheet and Javascript (Part-2)
 
Difference between dtd and xsd
Difference between dtd and xsdDifference between dtd and xsd
Difference between dtd and xsd
 
Asp.net state management
Asp.net state managementAsp.net state management
Asp.net state management
 
Client side scripting and server side scripting
Client side scripting and server side scriptingClient side scripting and server side scripting
Client side scripting and server side scripting
 
Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2
 
Transport Layer Services : Multiplexing And Demultiplexing
Transport Layer Services : Multiplexing And DemultiplexingTransport Layer Services : Multiplexing And Demultiplexing
Transport Layer Services : Multiplexing And Demultiplexing
 
Markup language classification, designing static and dynamic
Markup language classification, designing static and dynamicMarkup language classification, designing static and dynamic
Markup language classification, designing static and dynamic
 
Error handling and debugging in vb
Error handling and debugging in vbError handling and debugging in vb
Error handling and debugging in vb
 
Webinar : P, NP, NP-Hard , NP - Complete problems
Webinar : P, NP, NP-Hard , NP - Complete problems Webinar : P, NP, NP-Hard , NP - Complete problems
Webinar : P, NP, NP-Hard , NP - Complete problems
 
Complexity analysis - The Big O Notation
Complexity analysis - The Big O NotationComplexity analysis - The Big O Notation
Complexity analysis - The Big O Notation
 
Ajax ppt
Ajax pptAjax ppt
Ajax ppt
 
Avl trees
Avl treesAvl trees
Avl trees
 

Viewers also liked

[Basic HTML/CSS] 4. html - form tags
[Basic HTML/CSS] 4. html - form tags[Basic HTML/CSS] 4. html - form tags
[Basic HTML/CSS] 4. html - form tags
Hyejin Oh
 
[Basic HTML/CSS] 3. html - table tags
[Basic HTML/CSS] 3. html - table tags[Basic HTML/CSS] 3. html - table tags
[Basic HTML/CSS] 3. html - table tags
Hyejin Oh
 
Virtualization - Kernel Virtual Machine (KVM)
Virtualization - Kernel Virtual Machine (KVM)Virtualization - Kernel Virtual Machine (KVM)
Virtualization - Kernel Virtual Machine (KVM)
Wan Leung Wong
 
Tables and Forms in HTML
Tables and Forms in HTMLTables and Forms in HTML
Tables and Forms in HTML
Doncho Minkov
 
CSS-Cascading Style Sheets - Introduction
CSS-Cascading Style Sheets - IntroductionCSS-Cascading Style Sheets - Introduction
CSS-Cascading Style Sheets - Introduction
Mukesh Tekwani
 

Viewers also liked (20)

Web Engineering - Basic CSS Properties
Web Engineering - Basic CSS PropertiesWeb Engineering - Basic CSS Properties
Web Engineering - Basic CSS Properties
 
Web engineering - An overview about HTML
Web engineering -  An overview about HTMLWeb engineering -  An overview about HTML
Web engineering - An overview about HTML
 
Web engineering - HTML Form
Web engineering -  HTML FormWeb engineering -  HTML Form
Web engineering - HTML Form
 
Web Engineering
Web EngineeringWeb Engineering
Web Engineering
 
Web Engineering - Web Application Testing
Web Engineering - Web Application TestingWeb Engineering - Web Application Testing
Web Engineering - Web Application Testing
 
Web engineering - Measuring Effort Prediction Power and Accuracy
Web engineering - Measuring Effort Prediction Power and AccuracyWeb engineering - Measuring Effort Prediction Power and Accuracy
Web engineering - Measuring Effort Prediction Power and Accuracy
 
PROGRESS - CSS BASIC
PROGRESS - CSS BASICPROGRESS - CSS BASIC
PROGRESS - CSS BASIC
 
Angular js for beginners
Angular js for beginnersAngular js for beginners
Angular js for beginners
 
[Basic HTML/CSS] 4. html - form tags
[Basic HTML/CSS] 4. html - form tags[Basic HTML/CSS] 4. html - form tags
[Basic HTML/CSS] 4. html - form tags
 
[Basic HTML/CSS] 3. html - table tags
[Basic HTML/CSS] 3. html - table tags[Basic HTML/CSS] 3. html - table tags
[Basic HTML/CSS] 3. html - table tags
 
HTML Forms
HTML FormsHTML Forms
HTML Forms
 
Virtualization - Kernel Virtual Machine (KVM)
Virtualization - Kernel Virtual Machine (KVM)Virtualization - Kernel Virtual Machine (KVM)
Virtualization - Kernel Virtual Machine (KVM)
 
Qemu & KVM Guide #1 (intro & basic)
Qemu & KVM Guide #1 (intro & basic)Qemu & KVM Guide #1 (intro & basic)
Qemu & KVM Guide #1 (intro & basic)
 
Tables and Forms in HTML
Tables and Forms in HTMLTables and Forms in HTML
Tables and Forms in HTML
 
CSS-Cascading Style Sheets - Introduction
CSS-Cascading Style Sheets - IntroductionCSS-Cascading Style Sheets - Introduction
CSS-Cascading Style Sheets - Introduction
 
Cascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) helpCascading Style Sheets (CSS) help
Cascading Style Sheets (CSS) help
 
Web engineering lecture 1
Web engineering lecture 1Web engineering lecture 1
Web engineering lecture 1
 
Java script basics
Java script basicsJava script basics
Java script basics
 
Virtualization with KVM (Kernel-based Virtual Machine)
Virtualization with KVM (Kernel-based Virtual Machine)Virtualization with KVM (Kernel-based Virtual Machine)
Virtualization with KVM (Kernel-based Virtual Machine)
 
Virtualization Architecture & KVM
Virtualization Architecture & KVMVirtualization Architecture & KVM
Virtualization Architecture & KVM
 

Similar to Web Engineering - Introduction to CSS

Similar to Web Engineering - Introduction to CSS (20)

Kick start @ css
Kick start @ cssKick start @ css
Kick start @ css
 
Cascading Style Sheets By Mukesh
Cascading Style Sheets By MukeshCascading Style Sheets By Mukesh
Cascading Style Sheets By Mukesh
 
Css
CssCss
Css
 
Web technologies-course 03.pptx
Web technologies-course 03.pptxWeb technologies-course 03.pptx
Web technologies-course 03.pptx
 
2_css.pptx
2_css.pptx2_css.pptx
2_css.pptx
 
2_css.pptx
2_css.pptx2_css.pptx
2_css.pptx
 
2 introduction css
2 introduction css2 introduction css
2 introduction css
 
Css
CssCss
Css
 
Css
CssCss
Css
 
Understanding CSS for web development by software outsourcing company india
Understanding CSS for web development by software outsourcing company indiaUnderstanding CSS for web development by software outsourcing company india
Understanding CSS for web development by software outsourcing company india
 
Cascading style sheets - CSS
Cascading style sheets - CSSCascading style sheets - CSS
Cascading style sheets - CSS
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheets
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheets
 
CSS Font & Text style
CSS Font & Text style CSS Font & Text style
CSS Font & Text style
 
Css
CssCss
Css
 
CSS Overview
CSS OverviewCSS Overview
CSS Overview
 
WEB TECHNOLOGY Unit-2.pptx
WEB TECHNOLOGY Unit-2.pptxWEB TECHNOLOGY Unit-2.pptx
WEB TECHNOLOGY Unit-2.pptx
 
CSS Cascade Style Sheet
CSS Cascade Style SheetCSS Cascade Style Sheet
CSS Cascade Style Sheet
 
IT2255 Web Essentials - Unit II Web Designing
IT2255 Web Essentials - Unit II  Web DesigningIT2255 Web Essentials - Unit II  Web Designing
IT2255 Web Essentials - Unit II Web Designing
 
Intro to html, css & sass
Intro to html, css & sassIntro to html, css & sass
Intro to html, css & sass
 

Recently uploaded

Accounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdfAccounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdf
YibeltalNibretu
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 

Recently uploaded (20)

Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
 
Accounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdfAccounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdf
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Advances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfAdvances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdf
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resources
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptx
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 

Web Engineering - Introduction to CSS

  • 1. Web Engineering Lecture 05 Introduction to CSS University of Lahore Nosheen Qamar 1
  • 2. CASCADING STYLE SHEET • This is the language to add presentation styling to HTML documents. • CSS is a powerful and flexible way to add format to web page for resentation. • Through CSS it is relatively easy to take simple page of text and images, formatted to present as fully professional webpage. • CSS has a simple syntax, consist of selectors, properties and values it together make a style rules. • It gives developer find ways to control over how each element of page is formatted. • CSS styles can apply on HTML documents through several different ways. – Create an external CSS file. – Embed CSS code in HTML document. 2
  • 3. CSS Syntax • A style rule is made of three parts: • Selector: A selector is an HTML tag at which style will be applied. This could be any tag like <h1> or <table> etc. • Property: A property is a type of attribute of HTML tag. Put simply, all the HTML attributes are converted into CSS properties. They could be color or border etc. • Value: Values are assigned to properties. For example color property can have value either red or #F1F1F1 etc. • You can put CSS Style Rule Syntax as follows: selector { property: value; } • Example: You can define a table border as follows: table { border: 1px solid #C00FDF; } 3
  • 4. Applying CSS • There are three ways through which you apply CSS on your HTML doc.  Inline  Internal  External 4
  • 5. Inline CSS • You can also embed your CSS code in HTML document. • Example: <p style=“font-family: monospace;”> 5 INTERNAL CSS • <style></style> always placed between <head></head> tags. • Example: <style> p { line-height: 120%; } </style> EXTERNAL CSS FILE External CSS file will always place between <HEAD></HEAD> tags. <link rel=“stylesheet” type=“text/css” href=“main.css” />
  • 6. SELECTORS • There are three types of selectors:  Tag selectors  ID selectors  Class selectors 6
  • 7. Example Tag Selector <style> p { font-family: sans-serif; font-size: 15pt; line-height: 150%; } </style> 7 Tag selector
  • 8. Example Class Selector <style> .foo { font-family: sans-serif; font-size: 15pt; line-height: 150%; } </style> <p class=“foo”> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque sit amet lorem ligula. Nam pulvinar nunc ac magna aliquam quis sodales dui elementum. Fusce a lacus leo. Maecenas ut dui eu quam condimentum sagittis. </p> 8 class selector
  • 9. Example Class Selector <style> p.foo { font-family: sans-serif; font-size: 15pt; line-height: 150%; } </style> <body> <h1 class=“foo”></h1> <p class=“foo”></p> </body> 9 class selector
  • 10. Example ID Selector <style> #p1 { font-family: sans-serif; font-size: 15pt; line-height: 150%; } </style> <p id=“p1”> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque sit amet lorem ligula. Nam pulvinar nunc ac magna aliquam quis sodales dui elementum. Fusce a lacus leo. Maecenas ut dui eu quam condimentum sagittis. </p> 10 ID selector
  • 11. RULE for ID selector • There is only be one element in a document with a particular ID selector. • ID selector can only be used once in one element/tag. 11
  • 12. Descendant Selector <style> p a { font-family: sans-serif; font-size: 15pt; line-height: 150%; } </style> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit.. Nam pulvinar nunc ac magna aliquam quis sodales dui nunc sit elementum. <a href=“page1.html”>Donec eu nisi turpis,</a> sit amet rutrum leo. </p> Click <a href=“page2.html”>here</a> 12
  • 13. Grouping Selector • you can apply style to many selectors. • <style> h1, p, section { color: #35c; font-weight: bold; letter-spacing: .4em; } </style> 13
  • 14. Grouping Class & ID Selectors • you can apply style to many selectors. <style> #content, #footer, .supplement { position: absolute; left: 510px; width: 200px; } </style> 14
  • 15. PSEUDO SELECTOR <style> a:link { color: #008080; } a:hover { color: #FF0000; } </style> 15
  • 16. COMMENTS IN CSS <style> /* p { font-family: sans-serif; font-size: 15pt; } */ </style> 16
  • 17. CSS UNITS - Sizes • Relative length measurements: – px (pixels – size varies depending on screen resolution) – em (usually the height of a font’s uppercase M) – ex (usually the height of a font’s lowercase x) – Percentages (of the font’s default size) • Absolute-length measurements (units that do not vary in size): – in (inches) – cm (centimeters) – mm (millimeters) – pt (points; 1 pt = 1/72 in) – pc (picas; 1 pc = 12 pt) • Generally 1em = 12pt = 16px = 100% 17
  • 18. Unit Description Example % Defines a measurement as a percentage relative to another value, typically an enclosing element. p { font-size: 16pt; line-height: 125%; } cm Defines a measurement in centimeters. div {margin-bottom: 2cm;} em A relative measurement for height of a font in em spaces. Because an em unit is equivalent to the size of a given font, if you assign a font to 12pt, each “em” unit would be 12pt; thus 2em = 24pt. p { letter spacing: 7em; } ex This value defines a measurement relative to a font’s x-height. The x-height is determined by the height of the font’s lowercase letter x. p { font-size: 24pt; line-height: 3ex; } in Defines a measurement in inches. p { word-spacing: .15in;} mm Defines a measure in millimeters. p { word-spacing: 15mm;} pc Defines a measurement in picas. A pica is equivalent to 12 points. Thus, there are 6 picas per inch. p { font-size: 20pc;} 18
  • 19. 19 Unit Description Example pt Defines a measurement in points. A point is defined as 1/72nd of an inch. body {font-size: 18pt;} px Defines a measurement in screen pixels. p {padding: 25px;}
  • 20. CSS – Colors • You can specify your color values in various formats. 20 Format Syntax Example Hex Code #RRGGBB p {color: #FF0000; } Short Hex Code #RGB p {color: #6A7;} RGB % rgb(rrr%, ggg%, bbb%) p { color: rgb(50%, 50%, 50%); } RGB Absolute rgb(rrr, ggg, bbb) p { color: rgb(0, 0, 255); } keyword aqua, black etc. p { color: teal;}
  • 21. CSS Box Model • A set of rules collectively known as CSS Box Model describes the rectangular region occupied with HTML elements. • The main idea is that every element’s layout is composed of:  the actual element’s content area.  a border around the element.  a padding between the content and the border (inside the border)  a margin between the border and other content (outside the border) 21
  • 22. 22
  • 23. Block-Level Elements • A block level element in HTML create a “block” or “box”. • Browsers typically display the block-level element with a new line. • Block level elements may contain inline elements and other block-level elements. • The block level elements create “larger” structure than inline elements.
  • 24. List of Block-Level Elements <address> Contact information <figcaption> (HTML5) Figure caption <ol> Ordered list <article>(HTML5) Article content <figure>(HTML5) Groups media content with a caption <output>(HTML5) Form output <aside>(HTML5) Aside content <footer>(HTML5) Section or page footer <p> Paragraph <audio>(HTML5) Audio player <form> Input form <pre> Preformatted text <blockquote> Long (“block”) quotation <h1><h2><h3><h4><h5><h6> Heading levels 1 - 6 <section>(HTML5) Section of the page <canvas>(HTML5) Drawing canvas <header>(HTML5) Section or page header. <table> Table. <dd> Definition description <hgroup>(HTML5) Groups header information <tfoot> Table footer <div> Document division <hr> Horizontal rule (dividing line) <ul> Unordered list <dl> Definition list <fieldset> Field set label <video>(HTML5) Video player
  • 25. Inline Elements • An Inline element in HTML occupies only the space bounded by the tags that define the inline element. • Generally, inline elements may contain only data and other inline elements. • By default, inline elements do not begin with new line.
  • 26. The <span> & <div> Tags • A <span> ... </span> element defines an “inline” structure, i.e. it simply defines a stretch of text. Thus it can be used within a paragraph or table element without affecting the flow of the text. • A <div> ... </div> element defines a “block” structure. Usually the browser will place line breaks before and after this element, but otherwise it has no effect itself.
  • 27. CSS Font Properties • You can set following font properties of an element:  The font-family property is used to change the face of a font.  The font-style property is used to make a font italic or oblique.  The font-variant property is used to create a small-caps effect.  The font-weight property is used to increase or decrease how bold or light a font appears.  The font-size property is used to increase or decrease the size of a font.
  • 28. font-family • <p style="font-family: georgia, garamond, serif;"> This text is rendered in either georgia, garamond, or the default serif font depending on which font you have at your system. </p> • Output: This text is rendered in either georgia, garamond, or the default serif font depending on which font you have at your system.
  • 29. Generic Font Family • These are the generic name values for the font-family property, followed by an example of each that the browser might select from the user’s system fonts: 29 Generic font-family Names Example serif Times New Roman sans-serif Arial cursive Zapf-Chancery fantasy Western monospace Courier
  • 30. font-style • <p style="font-style: italic;"> This text will be rendered in italic style. </p> • Output: This text will be rendered in italic style. • Possible Values: normal, italic, oblique(more slanted than normal) 30
  • 31. font-size • <p style="font-size: 20pt;"> This font size is 20 pixels. </p> • Output: This font size is 20 points. • Possible values: px, small, xx-small, x-small, medium, large,31
  • 32. font-weight • <p style="font-weight: bold;"> This font is bold. </p> • Output: This font is bold. • Possible values: normal, bold, bolder, lighter, 100, 200, 300, 400, 500, 600, 700, 800, 900 32
  • 33. font-variant • <p style="font-variant: small-caps;"> This text will be rendered in small caps. </p> • Output: THIS TEXT WILL BE RENEDERED AS SMALL CAPS. • Possible values: normal, small-caps 33
  • 34. line-height • The line-height property is used to set the vertical distance between the baselines of adjacent lines of text. • You can use only this property with block- level elements. 34
  • 35. CSS Text Formatting • You can set following text properties of an element:  The color property is used to set the color of a text.  The letter-spacing property is used to add or subtract space between the letters.  The word-spacing property is used to add or subtract space between the words.  The text-indent property is used to indent the text of a paragraph.  The text-align property is used to align the text of a document.
  • 36.  The text-decoration property is used to underline, overline and strikethrough text.  The text-transform property is used to capitalize text or convert text to uppercase or lowercase letters.  The text-shadow property is used to set the text shadow around a text.  The white-space property is used to control the flow and formatting of text. 36
  • 37. color • <p style=“color: red;” > This text will be written in red. </p> • Output: This text will be written in red. • Possible values: any color name in any valid format. 37
  • 38. letter-spacing • <p style=“letter-spacing: 5px;” > This text is having space between letters. </p> • Output: T h i s t e x t i s h a v i n g s p a c e b e t w e e n l e t t e r s. • Possible values: 38
  • 39. word-spacing • <p style=“word-spacing: 5px;” > This text is having space between words. </p> • Output: This text is having space between words. • Possible values: 39
  • 40. text-indent • The text-indent property is used to indent only the first line of text within an element. • The default value for this property is 0. • It only applies to block-level elements. 40
  • 41. text-indent • <p style=“text-indent: 1cm;” > This text will have first line indent by 1cm. and this line will remain at its actual position. </p> • Output: This text will have first line indent by 1cm. and this line will remain at its actual position. 41
  • 42. text-decoration • <p style=“text-decoration: underline;” > This will be underline. </p> • Output: This will be underline. • Possible values: none, underline, overline, line-through, blink 42
  • 43. text-transform • <p style=“text-transform: uppercase;” > This will be in uppercase. </p> • Output: THIS WILL BE IN UPPERCASE. • Possible values: none, capitalize, uppercase, lowercase 43
  • 44. white-space • The white-space property is used to specify whether the blank space between words both horizontally and vertically is collapsed to a single character space or is retained and preserved as is. • The white space property is used with block-level elements. 44
  • 45. white-space • <p style=“white-space: pre;” > This text has a line break and the white-space pre setting tells the browser. </p> • Output: This text has a line break and the white-space pre setting tells the browser. 45
  • 46. text-shadow • <p style=“text-shadow: 4px 4px 8px blue;” > If your browser supports the css text- shadow property, this text will have a blue shadow. </p> • Output: • Possible values: 46