SlideShare a Scribd company logo
CHAPTER 4
INTRODUCTION TO CASCADING
STYLE SHEETS
(CSS) - Part 1
IT 210
Web-Based Design
1
O B J E C T I V E S
By the end of this chapter, you’ll be able to:
- Manage a website's appearance with style sheets.
- Use a style sheet to provide consistency across all website pages.
- Apply styles using the class attribute.
- Customize text properties such as font, size, and color with
precision.
2
OUTLINES FOR PART 1
 Introduction.
 Inline Styles.
 Embedded Style Sheets.
 Linking External Style Sheets.
Selectors in CSS
3
INTRODUCTION
The basic structure of every web page, HTML, is very plain on
its own. The beautiful websites that you see across the
internet are styled with a variety of tools, including CSS.
Cascading Style Sheets 3 (CSS3): is a language that is used in
combination with HTML that customizes how HTML elements
will appear. CSS can define styles and change the layout and
design of a sheet
CSS validated
 iigsaw.w3.org/css-validator/
 This tool can help you make sure that your code is correct
and will work on CSS3-compliant browsers. 4
INTRODUCTION
CSS: A New Philosophy
 Separate content from presentation!
Content
(HTML document)
Presentation
(CSS Document)
Title
Lorem ipsum dolor sit
amet, consectetuer
adipiscing elit.
Suspendisse at pede ut
purus malesuada
dictum. Donec
viaccumsan. Morbi at
• arcu vel elit ultricies
porta. Proin
tortor purus, luctus
non, aliquam nec,
interdum vel, ia
molestie. Praesent
augue tortor, convallis
eget, euismod
nonummy, lacinia ut,
risus.
Bold
Italics
Indent
Title
Lorem ipsum dolor sit amet, consectetuer adipiscing
elit. Suspendisse at pede ut purus malesuada
dictum. Donec vitae neque non magna aliquam
dictum.
• Vestibulum et odio et ipsum
• accumsan accumsan. Morbi at
• arcu vel elit ultricies porta. Proin
The Resulting
Page
Nice web done by CSS: http://seanhalpin.io/
WRITING CSS CODE IN HTML FILE
You can declare CSS codes in the HTML5, by:
1. INLINE STYLES:
CSS styles can be directly added to HTML elements by using the
style attribute in the element’s opening tag. Each style declaration
is ended with a semicolon. Styles added in this manner are known
as inline styles.
2. EMBEDDED STYLE: CSS code can be written in an HTML file by
enclosing the code in <style> tags. Code surrounded by <style>
tags will be interpreted as CSS syntax.
6
<h2 style="text-align: center;"> Centered text </h2>
<p style="color: blue; font-size:
18px;">Blue,text</p>
<head> <style> h1 { color : blue ; } </style> </head>
INLINE STYLES (CONT.) EXAMPLE (1)
7
INLINE STYLES
In Example (1) applies inline styles to p elements to alter their font
size and color.
 Each CSS property is followed by a colon (:) and the value of the
attribute and
 Multiple property declarations are separated by a semicolon (;)
8
<p style = "font-size: 20pt ; color:
deepskyblue ;">
it’s important to know that inline styles are a
quick way of directly styling an HTML element.
Fig. 4.1 | Using inline styles
INLINE STYLES (CONT.)
EXAMPLE (1) ON THE BROWSER
9
inline styles are a fast way of
styling HTML, but they also
have limitations. If you
wanted to style, for
example, multiple <h1>
elements, you would have
to add inline styling to each
element manually. In
addition, you would also
have to maintain the HTML
code when additional <h1>
elements are added.
https://colorhunt.co/ is a web site to help Designers and Artists to choose a
beautiful Color Palettes
INLINE STYLES (CONT.)
COLOR PROPERTY SETS TEXT COLOR
Color names and hexadecimal codes may be used as the color property value.
10
EMBEDDED (internal) STYLE SHEETS
 A second technique for using style sheets is embedded style
sheets, which enable you to embed a CSS3 codes in an
HTML5 document’s head section.
11
EMBEDDED STYLE SHEETS
EXAMPLE (2)
In this example create
an embedded style
sheet containing four
styles.
12
EMBEDDED STYLE SHEETS
EXAMPLE (2) CONT..
13
Fig. 4.3 | Embedded style sheet.
EMBEDDED STYLE SHEETS
EXAMPLE (2) OUTPUT
14
EMBEDDED STYLE SHEETS
EXAMPLE (2): EXPLAINING LINE 11 TO 18
Line 11: Styles placed in the head apply to matching elements wherever
they appear in the body. The style element’s type attribute specifies the
MIME (Multi purpose Internet Mail Extensions) type that describes the
style element’s content.
lines 12–17: declares the CSS rules for the style sheet.
15
Default in
HTML 5
STYLE SHEETS SYNTAX
 A style sheet consists of a set of rules.
 Each rule consists of one or more selectors and a declaration block.
 Selectors are separated by commas
 Declarations are separated by semicolons
 Properties and values are separated by colons
16
h1,h2,h3 { color: green; font-weight: bold; }
WRITING CSS CODE IN SEPARATE FILES
CSS code can be written in its own files to keep it separate from
the HTML code. The extension for CSS files is .css. These can be
linked to an HTML file using a <link> tag in the <head> section.
That called as External Style (highly recommended )
CSS rules in separate file .css extension linked via
<link rel="stylesheet" href=…> tag
17
WRITING CSS CODE IN SEPARATE FILES
<LINK> TAG
To link an external style sheet in html documents we use <link> tag.
Note: Link tag is void. (No need to close it)
o link tag has many elements some of them are:
18
Element
(Attribut
e)
Description
rel specify a relationship between two
documents
type specifies the MIME type of the related
document
href provides the URL for the document
WRITING CSS CODE IN SEPARATE FILES
 External style sheets are separate documents that contain
only CSS rules.
 Help create a uniform look for a website:
oSeparate pages can all use the same styles.
oModifying a single style-sheet file makes changes to styles
across an entire website (or to a portion of one).
 When changes to the styles are required, you need to
modify only a single CSS file to make style changes across
all the pages that use those styles. This concept is
sometimes known as skinning.
19
body { background-color:
#E6E6FA;
color: #000000;}
h2 { color: #003366; }
LINKING EXTERNAL STYLE SHEETS
Multiple web pages can associate with the same external
style sheet file.
20
site.css index.html
clients.html
about.html
Etc…
WHAT IS THE PREFERRED WAY OF INCLUDING CSS WITHIN A
PROJECT? HOW DO I KNOW WHEN TO USE INLINE STYLES, THE
TAGS, OR A .CSS FILE?
As a web developer you will eventually come across HTML documents
which include CSS either inline with style attributes or within the <style>
tags at the head of the document. Hence, it is important to be aware of
all the various ways to include CSS in a project.
That having been said, mashing HTML and CSS together is not a great
habit to get into. As developers we want to “separate our concerns”
because this usually creates codebases that are more flexible, readable,
and maintainable. As such, keeping our CSS contained within a separate
.css file is the preferred way of including CSS within most projects.
21
SELECTORS IN CSS
1. CSS Type Selectors
 used to match all elements of a given type or tag name
 For example, in HTML, the tag for a paragraph element
is <p>. The CSS syntax for selecting <p> elements is:
p {
…..
}
22
SELECTORS IN CSS
2. CSS class selectors
 it matches elements based on the contents of their class
attribute. a . needs to be prepended.
23
For example, consider the following HTML:
<p class="brand">Sole Shoe Company</p>
The paragraph element in the example above has a class
attribute within the <p> tag.
The class attribute is set to "brand". To select this element
using CSS, we could use the following CSS selector:
.brand {
}
SELECTORS IN CSS
3. CSS ID selectorsIt matches elements based on the contents of their id
attribute. The values of id attribute should be unique.
24
Explain:
If an HTML element needs to be styled uniquely (no
matter what classes are applied to the element), we
can add an ID to the element to the tag:
<h1 id="large-title"> ... </h1>
Then, CSS can select HTML elements by their id
attribute. To select an id element, CSS prepends the
id name with a hashtag (#). For instance, if we wanted
to select the HTML element in the example above, it
would look like this:
#large-title {
SELECTORS IN CSS
4. Groups of CSS Selectors
 Match multiple selectors to the same CSS rule, using a
comma-separated list. In this example, the text for both h1
and h2 is set to red.
Example:
h1, h2 {
color: red; }
25
SELECTORS IN CSS
5. Chaining Selectors
 that rule sets apply only to elements that match all criteria.
Example:
26
/* Select h3 elements with the section-heading class
*/
h3.section-heading {
color: blue; }
/* Select elements with the section-heading and
button class */
.section-heading .button {
cursor: pointer; }
MULTIPLE CLASSES
For instance, perhaps there’s a heading element that needs to be green and
bold. You could write two CSS rules like so:
.green { color: green; }
.bold { font-weight: bold; }
Then, you could include both of these classes on one HTML element like this:
<h1 class="green bold"> ... </h1>
We can add multiple classes to an HTML element’s class attribute by separating
them with a space. This enables us to mix and match CSS classes to create
many unique styles without writing a custom class for every style combination
needed. 27
CLASS VS ID
classes are meant to be used many times
ID is meant to style only one element.
IDs override the styles of tags and classes.
ID attribute should be unique
28
SELECTOR SPECIFICITY
The most specific selector type is the ID selector, followed by
class selectors, followed by type selectors.
In this example, only color: blue will be implemented as it has
an ID selector whereas color: red has a type selector
Specificity is a ranking system that is used when there are
multiple conflicting property values that point to the same
element. When determining which rule to apply, the selector
with the highest specificity wins out.
29
h1 #header { color: blue; } /*implemented*/
h1 { color: red; } /*not implemented*/
CSS !IMPORTANT RULE
The CSS !important rule is used on declarations to override
any other declarations for a property and ignore selector
specificity.
!important rules will ensure that a specific declaration always
applies to the matched elements.
However, generally it is good to avoid using !important as
bad practice.
30
#column-one {
width: 200px !important; }
.post-title {
color: blue !important; }
Review CSS Selectors
•CSS can change the look of HTML elements. In order to do this, CSS must select HTML
elements.
•CSS can select HTML elements by tag, class, or ID.
•Multiple CSS classes can be applied to one HTML element.
•Classes can be reusable, while IDs can only be used once.
•IDs are more specific than classes, and classes are more specific than tags.
•The !important flag will override any style, however it should almost never be used, as it
is extremely difficult to override.
•Multiple unrelated selectors can receive the same styles by separating the selector
names with commas.
31
SOME OF CSS FONT PROPERTY
font-family Property
font-family property specifies the name of the font to use.
32
Fig. 4.5 | Generic font families.
SOME OF CSS FONT PROPERTY
font-size Property
 font-size property: specifies the size used to render the font.
 You can specify a point size such(12pt) or a relative value such as (xx-
small, x-small, small, smaller, medium, large, larger, x-large and xx-
large).
 Relative font-size values are preferred over points, because an author
does not know the specific measurements of each client’s display.
 Relative values permit more flexible viewing of web pages.
 For example, users can change font sizes the browser displays for
readability.
33
SOME OF CSS FONT PROPERTY
font-weight property
 font-weight property : specifies the “boldness” of
text. Possible values are:
o bold
o normal (the default)
o bolder (bolder than bold text)
o lighter (lighter than normal text)
34
SOME OF CSS FONT PROPERTY
text-align property
 The text-align property places text in the left, right,
or center of its parent container.
color property :
 defines the color of the text.
35
VALUES IN THE CSS RULES
 Colors are set in RGB format (decimal or hex):
o Example: #a0a6aa = rgb(160, 166, 170)
o Predefined color aliases exist: black, blue, etc.
 Numeric values are specified in:
o Pixels, ems, e.g. 12px , 1em
o Points, inches, centimeters, millimeters
• E.g. 10pt , 1in, 1cm, 1mm
o Percentages, e.g. 50%
o Zero can be used with no unit: border: 0; 36

More Related Content

Similar to Lecture 9 CSS part 1.pptxType Classification (20)

3. CSS
3. CSS3. CSS
3. CSS
Pavle Đorđević
 
Css week11 2019 2020 for g10 by eng.osama ghandour
Css week11 2019 2020 for g10 by eng.osama ghandourCss week11 2019 2020 for g10 by eng.osama ghandour
Css week11 2019 2020 for g10 by eng.osama ghandour
Osama Ghandour Geris
 
Unit 2-CSS & Bootstrap.ppt
Unit 2-CSS & Bootstrap.pptUnit 2-CSS & Bootstrap.ppt
Unit 2-CSS & Bootstrap.ppt
TusharTikia
 
Chapter 4a cascade style sheet css
Chapter 4a cascade style sheet cssChapter 4a cascade style sheet css
Chapter 4a cascade style sheet css
Tesfaye Yenealem
 
CSS.pptx
CSS.pptxCSS.pptx
CSS.pptx
VijayKumarLokanadam
 
IP - Lecture 6, 7 Chapter-3 (3).ppt
IP - Lecture 6, 7 Chapter-3 (3).pptIP - Lecture 6, 7 Chapter-3 (3).ppt
IP - Lecture 6, 7 Chapter-3 (3).ppt
kassahungebrie
 
CSS Fundamentals: selectors and Properties
CSS Fundamentals: selectors and PropertiesCSS Fundamentals: selectors and Properties
CSS Fundamentals: selectors and Properties
Pedro Valente
 
Introduction to CSS.pptx web for web web
Introduction to CSS.pptx web for web webIntroduction to CSS.pptx web for web web
Introduction to CSS.pptx web for web web
compengwaelalahmar
 
Week11 Lecture: CSS
Week11 Lecture: CSSWeek11 Lecture: CSS
Week11 Lecture: CSS
Katherine McCurdy-Lapierre, R.G.D.
 
ch04-css-basics_final.ppt
ch04-css-basics_final.pptch04-css-basics_final.ppt
ch04-css-basics_final.ppt
GmachImen
 
Intro to HTML and CSS - Class 2 Slides
Intro to HTML and CSS - Class 2 SlidesIntro to HTML and CSS - Class 2 Slides
Intro to HTML and CSS - Class 2 Slides
Heather Rock
 
Web technologies-course 03.pptx
Web technologies-course 03.pptxWeb technologies-course 03.pptx
Web technologies-course 03.pptx
Stefan Oprea
 
Cascading style sheet, CSS Box model, Table in CSS
Cascading style sheet, CSS Box model, Table in CSSCascading style sheet, CSS Box model, Table in CSS
Cascading style sheet, CSS Box model, Table in CSS
SherinRappai
 
Shyam sunder Rajasthan Computer
Shyam sunder Rajasthan ComputerShyam sunder Rajasthan Computer
Shyam sunder Rajasthan Computer
shyamverma305
 
Cascading style sheet an introduction
Cascading style sheet   an introductionCascading style sheet   an introduction
Cascading style sheet an introduction
Himanshu Pathak
 
CSS
CSSCSS
CSS
Raja Kumar Ranjan
 
Css
CssCss
Css
Abhishek Kesharwani
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
Mukesh Tekwani
 
Cascading Styling Sheets(CSS) simple design language intended to transform th...
Cascading Styling Sheets(CSS) simple design language intended to transform th...Cascading Styling Sheets(CSS) simple design language intended to transform th...
Cascading Styling Sheets(CSS) simple design language intended to transform th...
JebaRaj26
 
LIS3353 SP12 Week 13
LIS3353 SP12 Week 13LIS3353 SP12 Week 13
LIS3353 SP12 Week 13
Amanda Case
 
Css week11 2019 2020 for g10 by eng.osama ghandour
Css week11 2019 2020 for g10 by eng.osama ghandourCss week11 2019 2020 for g10 by eng.osama ghandour
Css week11 2019 2020 for g10 by eng.osama ghandour
Osama Ghandour Geris
 
Unit 2-CSS & Bootstrap.ppt
Unit 2-CSS & Bootstrap.pptUnit 2-CSS & Bootstrap.ppt
Unit 2-CSS & Bootstrap.ppt
TusharTikia
 
Chapter 4a cascade style sheet css
Chapter 4a cascade style sheet cssChapter 4a cascade style sheet css
Chapter 4a cascade style sheet css
Tesfaye Yenealem
 
IP - Lecture 6, 7 Chapter-3 (3).ppt
IP - Lecture 6, 7 Chapter-3 (3).pptIP - Lecture 6, 7 Chapter-3 (3).ppt
IP - Lecture 6, 7 Chapter-3 (3).ppt
kassahungebrie
 
CSS Fundamentals: selectors and Properties
CSS Fundamentals: selectors and PropertiesCSS Fundamentals: selectors and Properties
CSS Fundamentals: selectors and Properties
Pedro Valente
 
Introduction to CSS.pptx web for web web
Introduction to CSS.pptx web for web webIntroduction to CSS.pptx web for web web
Introduction to CSS.pptx web for web web
compengwaelalahmar
 
ch04-css-basics_final.ppt
ch04-css-basics_final.pptch04-css-basics_final.ppt
ch04-css-basics_final.ppt
GmachImen
 
Intro to HTML and CSS - Class 2 Slides
Intro to HTML and CSS - Class 2 SlidesIntro to HTML and CSS - Class 2 Slides
Intro to HTML and CSS - Class 2 Slides
Heather Rock
 
Web technologies-course 03.pptx
Web technologies-course 03.pptxWeb technologies-course 03.pptx
Web technologies-course 03.pptx
Stefan Oprea
 
Cascading style sheet, CSS Box model, Table in CSS
Cascading style sheet, CSS Box model, Table in CSSCascading style sheet, CSS Box model, Table in CSS
Cascading style sheet, CSS Box model, Table in CSS
SherinRappai
 
Shyam sunder Rajasthan Computer
Shyam sunder Rajasthan ComputerShyam sunder Rajasthan Computer
Shyam sunder Rajasthan Computer
shyamverma305
 
Cascading style sheet an introduction
Cascading style sheet   an introductionCascading style sheet   an introduction
Cascading style sheet an introduction
Himanshu Pathak
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
Mukesh Tekwani
 
Cascading Styling Sheets(CSS) simple design language intended to transform th...
Cascading Styling Sheets(CSS) simple design language intended to transform th...Cascading Styling Sheets(CSS) simple design language intended to transform th...
Cascading Styling Sheets(CSS) simple design language intended to transform th...
JebaRaj26
 
LIS3353 SP12 Week 13
LIS3353 SP12 Week 13LIS3353 SP12 Week 13
LIS3353 SP12 Week 13
Amanda Case
 

More from ZahouAmel1 (18)

2- lec_2.pptxDesigning with Type, SpacingDesigning with Type, SpacingDesignin...
2- lec_2.pptxDesigning with Type, SpacingDesigning with Type, SpacingDesignin...2- lec_2.pptxDesigning with Type, SpacingDesigning with Type, SpacingDesignin...
2- lec_2.pptxDesigning with Type, SpacingDesigning with Type, SpacingDesignin...
ZahouAmel1
 
1-Lect_1.pptxLecture 5 array in PHP.pptx
1-Lect_1.pptxLecture 5 array in PHP.pptx1-Lect_1.pptxLecture 5 array in PHP.pptx
1-Lect_1.pptxLecture 5 array in PHP.pptx
ZahouAmel1
 
Lecture 8 PHP and MYSQL part 2.ppType Classificationtx
Lecture 8 PHP and MYSQL part 2.ppType ClassificationtxLecture 8 PHP and MYSQL part 2.ppType Classificationtx
Lecture 8 PHP and MYSQL part 2.ppType Classificationtx
ZahouAmel1
 
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvvLecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
ZahouAmel1
 
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvvLecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
ZahouAmel1
 
Lecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 10 CSS part 2.pptxvvvvvvvvvvvvvvLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
ZahouAmel1
 
Lec 1 Introduction to Computer and Information Technology #1.pptx
Lec 1 Introduction to Computer and Information Technology #1.pptxLec 1 Introduction to Computer and Information Technology #1.pptx
Lec 1 Introduction to Computer and Information Technology #1.pptx
ZahouAmel1
 
DB-Lec1.pptxUpdatedpython.pptxUpdatedpython.pptx
DB-Lec1.pptxUpdatedpython.pptxUpdatedpython.pptxDB-Lec1.pptxUpdatedpython.pptxUpdatedpython.pptx
DB-Lec1.pptxUpdatedpython.pptxUpdatedpython.pptx
ZahouAmel1
 
DB- lec2.pptxUpdatedpython.pptxUpdatedpy
DB- lec2.pptxUpdatedpython.pptxUpdatedpyDB- lec2.pptxUpdatedpython.pptxUpdatedpy
DB- lec2.pptxUpdatedpython.pptxUpdatedpy
ZahouAmel1
 
Updatedpython.pptxUpdatedpython.pptxUpdatedpython.pptx
Updatedpython.pptxUpdatedpython.pptxUpdatedpython.pptxUpdatedpython.pptxUpdatedpython.pptxUpdatedpython.pptx
Updatedpython.pptxUpdatedpython.pptxUpdatedpython.pptx
ZahouAmel1
 
4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptx
4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptx
4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptx
ZahouAmel1
 
5-LEC- 5.pptxTransport Layer. Transport Layer Protocols
5-LEC- 5.pptxTransport Layer.  Transport Layer Protocols5-LEC- 5.pptxTransport Layer.  Transport Layer Protocols
5-LEC- 5.pptxTransport Layer. Transport Layer Protocols
ZahouAmel1
 
6-LEC- 6.pptx Network Layer. Addressing Subnetting Mask (default and subnet) ...
6-LEC- 6.pptx Network Layer. Addressing Subnetting Mask (default and subnet) ...6-LEC- 6.pptx Network Layer. Addressing Subnetting Mask (default and subnet) ...
6-LEC- 6.pptx Network Layer. Addressing Subnetting Mask (default and subnet) ...
ZahouAmel1
 
7-Lect_7 .pptxNetwork Layer. Addressing Subnetting Mask (default and subnet) ...
7-Lect_7 .pptxNetwork Layer. Addressing Subnetting Mask (default and subnet) ...7-Lect_7 .pptxNetwork Layer. Addressing Subnetting Mask (default and subnet) ...
7-Lect_7 .pptxNetwork Layer. Addressing Subnetting Mask (default and subnet) ...
ZahouAmel1
 
7-Lect_7 .pptxNetwork LayerNetwork Layer
7-Lect_7 .pptxNetwork LayerNetwork Layer7-Lect_7 .pptxNetwork LayerNetwork Layer
7-Lect_7 .pptxNetwork LayerNetwork Layer
ZahouAmel1
 
8-Lect_8 Addressing the Network.tcp.pptx
8-Lect_8 Addressing the Network.tcp.pptx8-Lect_8 Addressing the Network.tcp.pptx
8-Lect_8 Addressing the Network.tcp.pptx
ZahouAmel1
 
9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptx
9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptx
9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptx
ZahouAmel1
 
9-Lect_9-2.pptx DataLink Layer DataLink Layer
9-Lect_9-2.pptx DataLink Layer DataLink Layer9-Lect_9-2.pptx DataLink Layer DataLink Layer
9-Lect_9-2.pptx DataLink Layer DataLink Layer
ZahouAmel1
 
2- lec_2.pptxDesigning with Type, SpacingDesigning with Type, SpacingDesignin...
2- lec_2.pptxDesigning with Type, SpacingDesigning with Type, SpacingDesignin...2- lec_2.pptxDesigning with Type, SpacingDesigning with Type, SpacingDesignin...
2- lec_2.pptxDesigning with Type, SpacingDesigning with Type, SpacingDesignin...
ZahouAmel1
 
1-Lect_1.pptxLecture 5 array in PHP.pptx
1-Lect_1.pptxLecture 5 array in PHP.pptx1-Lect_1.pptxLecture 5 array in PHP.pptx
1-Lect_1.pptxLecture 5 array in PHP.pptx
ZahouAmel1
 
Lecture 8 PHP and MYSQL part 2.ppType Classificationtx
Lecture 8 PHP and MYSQL part 2.ppType ClassificationtxLecture 8 PHP and MYSQL part 2.ppType Classificationtx
Lecture 8 PHP and MYSQL part 2.ppType Classificationtx
ZahouAmel1
 
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvvLecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 5 array in PHP.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
ZahouAmel1
 
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvvLecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 2 HTML part 1.pptxLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
ZahouAmel1
 
Lecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 10 CSS part 2.pptxvvvvvvvvvvvvvvLecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
Lecture 10 CSS part 2.pptxvvvvvvvvvvvvvv
ZahouAmel1
 
Lec 1 Introduction to Computer and Information Technology #1.pptx
Lec 1 Introduction to Computer and Information Technology #1.pptxLec 1 Introduction to Computer and Information Technology #1.pptx
Lec 1 Introduction to Computer and Information Technology #1.pptx
ZahouAmel1
 
DB-Lec1.pptxUpdatedpython.pptxUpdatedpython.pptx
DB-Lec1.pptxUpdatedpython.pptxUpdatedpython.pptxDB-Lec1.pptxUpdatedpython.pptxUpdatedpython.pptx
DB-Lec1.pptxUpdatedpython.pptxUpdatedpython.pptx
ZahouAmel1
 
DB- lec2.pptxUpdatedpython.pptxUpdatedpy
DB- lec2.pptxUpdatedpython.pptxUpdatedpyDB- lec2.pptxUpdatedpython.pptxUpdatedpy
DB- lec2.pptxUpdatedpython.pptxUpdatedpy
ZahouAmel1
 
Updatedpython.pptxUpdatedpython.pptxUpdatedpython.pptx
Updatedpython.pptxUpdatedpython.pptxUpdatedpython.pptxUpdatedpython.pptxUpdatedpython.pptxUpdatedpython.pptx
Updatedpython.pptxUpdatedpython.pptxUpdatedpython.pptx
ZahouAmel1
 
4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptx
4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptx
4-Lect_4-2.pptx4-Lect_4-2.pptx4-Lect_4-2.pptx
ZahouAmel1
 
5-LEC- 5.pptxTransport Layer. Transport Layer Protocols
5-LEC- 5.pptxTransport Layer.  Transport Layer Protocols5-LEC- 5.pptxTransport Layer.  Transport Layer Protocols
5-LEC- 5.pptxTransport Layer. Transport Layer Protocols
ZahouAmel1
 
6-LEC- 6.pptx Network Layer. Addressing Subnetting Mask (default and subnet) ...
6-LEC- 6.pptx Network Layer. Addressing Subnetting Mask (default and subnet) ...6-LEC- 6.pptx Network Layer. Addressing Subnetting Mask (default and subnet) ...
6-LEC- 6.pptx Network Layer. Addressing Subnetting Mask (default and subnet) ...
ZahouAmel1
 
7-Lect_7 .pptxNetwork Layer. Addressing Subnetting Mask (default and subnet) ...
7-Lect_7 .pptxNetwork Layer. Addressing Subnetting Mask (default and subnet) ...7-Lect_7 .pptxNetwork Layer. Addressing Subnetting Mask (default and subnet) ...
7-Lect_7 .pptxNetwork Layer. Addressing Subnetting Mask (default and subnet) ...
ZahouAmel1
 
7-Lect_7 .pptxNetwork LayerNetwork Layer
7-Lect_7 .pptxNetwork LayerNetwork Layer7-Lect_7 .pptxNetwork LayerNetwork Layer
7-Lect_7 .pptxNetwork LayerNetwork Layer
ZahouAmel1
 
8-Lect_8 Addressing the Network.tcp.pptx
8-Lect_8 Addressing the Network.tcp.pptx8-Lect_8 Addressing the Network.tcp.pptx
8-Lect_8 Addressing the Network.tcp.pptx
ZahouAmel1
 
9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptx
9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptx
9-Lect_9-1.pptx9-Lect_9-1.pptx9-Lect_9-1.pptx
ZahouAmel1
 
9-Lect_9-2.pptx DataLink Layer DataLink Layer
9-Lect_9-2.pptx DataLink Layer DataLink Layer9-Lect_9-2.pptx DataLink Layer DataLink Layer
9-Lect_9-2.pptx DataLink Layer DataLink Layer
ZahouAmel1
 

Recently uploaded (20)

New Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDBNew Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDB
ScyllaDB
 
Master tester AI toolbox - Kari Kakkonen at Testaus ja AI 2025 Professio
Master tester AI toolbox - Kari Kakkonen at Testaus ja AI 2025 ProfessioMaster tester AI toolbox - Kari Kakkonen at Testaus ja AI 2025 Professio
Master tester AI toolbox - Kari Kakkonen at Testaus ja AI 2025 Professio
Kari Kakkonen
 
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Nikki Chapple
 
Introducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and ARIntroducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and AR
Safe Software
 
Supercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMsSupercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMs
Francesco Corti
 
Security Operations and the Defense Analyst - Splunk Certificate
Security Operations and the Defense Analyst - Splunk CertificateSecurity Operations and the Defense Analyst - Splunk Certificate
Security Operations and the Defense Analyst - Splunk Certificate
VICTOR MAESTRE RAMIREZ
 
A Comprehensive Guide on Integrating Monoova Payment Gateway
A Comprehensive Guide on Integrating Monoova Payment GatewayA Comprehensive Guide on Integrating Monoova Payment Gateway
A Comprehensive Guide on Integrating Monoova Payment Gateway
danielle hunter
 
AI in Java - MCP in Action, Langchain4J-CDI, SmallRye-LLM, Spring AI
AI in Java - MCP in Action, Langchain4J-CDI, SmallRye-LLM, Spring AIAI in Java - MCP in Action, Langchain4J-CDI, SmallRye-LLM, Spring AI
AI in Java - MCP in Action, Langchain4J-CDI, SmallRye-LLM, Spring AI
Buhake Sindi
 
AI Trends - Mary Meeker
AI Trends - Mary MeekerAI Trends - Mary Meeker
AI Trends - Mary Meeker
Razin Mustafiz
 
Let’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack CommunityLet’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack Community
SanjeetMishra29
 
Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...
pranavbodhak
 
Building Agents with LangGraph & Gemini
Building Agents with LangGraph &  GeminiBuilding Agents with LangGraph &  Gemini
Building Agents with LangGraph & Gemini
HusseinMalikMammadli
 
With Claude 4, Anthropic redefines AI capabilities, effectively unleashing a ...
With Claude 4, Anthropic redefines AI capabilities, effectively unleashing a ...With Claude 4, Anthropic redefines AI capabilities, effectively unleashing a ...
With Claude 4, Anthropic redefines AI capabilities, effectively unleashing a ...
SOFTTECHHUB
 
Fully Open-Source Private Clouds: Freedom, Security, and Control
Fully Open-Source Private Clouds: Freedom, Security, and ControlFully Open-Source Private Clouds: Freedom, Security, and Control
Fully Open-Source Private Clouds: Freedom, Security, and Control
ShapeBlue
 
MCP Dev Summit - Pragmatic Scaling of Enterprise GenAI with MCP
MCP Dev Summit - Pragmatic Scaling of Enterprise GenAI with MCPMCP Dev Summit - Pragmatic Scaling of Enterprise GenAI with MCP
MCP Dev Summit - Pragmatic Scaling of Enterprise GenAI with MCP
Sambhav Kothari
 
TrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy ContractingTrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy Contracting
TrustArc
 
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure ModesCognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Dr. Tathagat Varma
 
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk TechniciansOffshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
john823664
 
Agentic AI - The New Era of Intelligence
Agentic AI - The New Era of IntelligenceAgentic AI - The New Era of Intelligence
Agentic AI - The New Era of Intelligence
Muzammil Shah
 
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Lorenzo Miniero
 
New Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDBNew Ways to Reduce Database Costs with ScyllaDB
New Ways to Reduce Database Costs with ScyllaDB
ScyllaDB
 
Master tester AI toolbox - Kari Kakkonen at Testaus ja AI 2025 Professio
Master tester AI toolbox - Kari Kakkonen at Testaus ja AI 2025 ProfessioMaster tester AI toolbox - Kari Kakkonen at Testaus ja AI 2025 Professio
Master tester AI toolbox - Kari Kakkonen at Testaus ja AI 2025 Professio
Kari Kakkonen
 
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Nikki Chapple
 
Introducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and ARIntroducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and AR
Safe Software
 
Supercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMsSupercharge Your AI Development with Local LLMs
Supercharge Your AI Development with Local LLMs
Francesco Corti
 
Security Operations and the Defense Analyst - Splunk Certificate
Security Operations and the Defense Analyst - Splunk CertificateSecurity Operations and the Defense Analyst - Splunk Certificate
Security Operations and the Defense Analyst - Splunk Certificate
VICTOR MAESTRE RAMIREZ
 
A Comprehensive Guide on Integrating Monoova Payment Gateway
A Comprehensive Guide on Integrating Monoova Payment GatewayA Comprehensive Guide on Integrating Monoova Payment Gateway
A Comprehensive Guide on Integrating Monoova Payment Gateway
danielle hunter
 
AI in Java - MCP in Action, Langchain4J-CDI, SmallRye-LLM, Spring AI
AI in Java - MCP in Action, Langchain4J-CDI, SmallRye-LLM, Spring AIAI in Java - MCP in Action, Langchain4J-CDI, SmallRye-LLM, Spring AI
AI in Java - MCP in Action, Langchain4J-CDI, SmallRye-LLM, Spring AI
Buhake Sindi
 
AI Trends - Mary Meeker
AI Trends - Mary MeekerAI Trends - Mary Meeker
AI Trends - Mary Meeker
Razin Mustafiz
 
Let’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack CommunityLet’s Get Slack Certified! 🚀- Slack Community
Let’s Get Slack Certified! 🚀- Slack Community
SanjeetMishra29
 
Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...
pranavbodhak
 
Building Agents with LangGraph & Gemini
Building Agents with LangGraph &  GeminiBuilding Agents with LangGraph &  Gemini
Building Agents with LangGraph & Gemini
HusseinMalikMammadli
 
With Claude 4, Anthropic redefines AI capabilities, effectively unleashing a ...
With Claude 4, Anthropic redefines AI capabilities, effectively unleashing a ...With Claude 4, Anthropic redefines AI capabilities, effectively unleashing a ...
With Claude 4, Anthropic redefines AI capabilities, effectively unleashing a ...
SOFTTECHHUB
 
Fully Open-Source Private Clouds: Freedom, Security, and Control
Fully Open-Source Private Clouds: Freedom, Security, and ControlFully Open-Source Private Clouds: Freedom, Security, and Control
Fully Open-Source Private Clouds: Freedom, Security, and Control
ShapeBlue
 
MCP Dev Summit - Pragmatic Scaling of Enterprise GenAI with MCP
MCP Dev Summit - Pragmatic Scaling of Enterprise GenAI with MCPMCP Dev Summit - Pragmatic Scaling of Enterprise GenAI with MCP
MCP Dev Summit - Pragmatic Scaling of Enterprise GenAI with MCP
Sambhav Kothari
 
TrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy ContractingTrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy Contracting
TrustArc
 
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure ModesCognitive Chasms - A Typology of GenAI Failure Failure Modes
Cognitive Chasms - A Typology of GenAI Failure Failure Modes
Dr. Tathagat Varma
 
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk TechniciansOffshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
john823664
 
Agentic AI - The New Era of Intelligence
Agentic AI - The New Era of IntelligenceAgentic AI - The New Era of Intelligence
Agentic AI - The New Era of Intelligence
Muzammil Shah
 
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Multistream in SIP and NoSIP @ OpenSIPS Summit 2025
Lorenzo Miniero
 

Lecture 9 CSS part 1.pptxType Classification

  • 1. CHAPTER 4 INTRODUCTION TO CASCADING STYLE SHEETS (CSS) - Part 1 IT 210 Web-Based Design 1
  • 2. O B J E C T I V E S By the end of this chapter, you’ll be able to: - Manage a website's appearance with style sheets. - Use a style sheet to provide consistency across all website pages. - Apply styles using the class attribute. - Customize text properties such as font, size, and color with precision. 2
  • 3. OUTLINES FOR PART 1  Introduction.  Inline Styles.  Embedded Style Sheets.  Linking External Style Sheets. Selectors in CSS 3
  • 4. INTRODUCTION The basic structure of every web page, HTML, is very plain on its own. The beautiful websites that you see across the internet are styled with a variety of tools, including CSS. Cascading Style Sheets 3 (CSS3): is a language that is used in combination with HTML that customizes how HTML elements will appear. CSS can define styles and change the layout and design of a sheet CSS validated  iigsaw.w3.org/css-validator/  This tool can help you make sure that your code is correct and will work on CSS3-compliant browsers. 4
  • 5. INTRODUCTION CSS: A New Philosophy  Separate content from presentation! Content (HTML document) Presentation (CSS Document) Title Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse at pede ut purus malesuada dictum. Donec viaccumsan. Morbi at • arcu vel elit ultricies porta. Proin tortor purus, luctus non, aliquam nec, interdum vel, ia molestie. Praesent augue tortor, convallis eget, euismod nonummy, lacinia ut, risus. Bold Italics Indent Title Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse at pede ut purus malesuada dictum. Donec vitae neque non magna aliquam dictum. • Vestibulum et odio et ipsum • accumsan accumsan. Morbi at • arcu vel elit ultricies porta. Proin The Resulting Page Nice web done by CSS: http://seanhalpin.io/
  • 6. WRITING CSS CODE IN HTML FILE You can declare CSS codes in the HTML5, by: 1. INLINE STYLES: CSS styles can be directly added to HTML elements by using the style attribute in the element’s opening tag. Each style declaration is ended with a semicolon. Styles added in this manner are known as inline styles. 2. EMBEDDED STYLE: CSS code can be written in an HTML file by enclosing the code in <style> tags. Code surrounded by <style> tags will be interpreted as CSS syntax. 6 <h2 style="text-align: center;"> Centered text </h2> <p style="color: blue; font-size: 18px;">Blue,text</p> <head> <style> h1 { color : blue ; } </style> </head>
  • 7. INLINE STYLES (CONT.) EXAMPLE (1) 7
  • 8. INLINE STYLES In Example (1) applies inline styles to p elements to alter their font size and color.  Each CSS property is followed by a colon (:) and the value of the attribute and  Multiple property declarations are separated by a semicolon (;) 8 <p style = "font-size: 20pt ; color: deepskyblue ;"> it’s important to know that inline styles are a quick way of directly styling an HTML element.
  • 9. Fig. 4.1 | Using inline styles INLINE STYLES (CONT.) EXAMPLE (1) ON THE BROWSER 9 inline styles are a fast way of styling HTML, but they also have limitations. If you wanted to style, for example, multiple <h1> elements, you would have to add inline styling to each element manually. In addition, you would also have to maintain the HTML code when additional <h1> elements are added.
  • 10. https://colorhunt.co/ is a web site to help Designers and Artists to choose a beautiful Color Palettes INLINE STYLES (CONT.) COLOR PROPERTY SETS TEXT COLOR Color names and hexadecimal codes may be used as the color property value. 10
  • 11. EMBEDDED (internal) STYLE SHEETS  A second technique for using style sheets is embedded style sheets, which enable you to embed a CSS3 codes in an HTML5 document’s head section. 11
  • 12. EMBEDDED STYLE SHEETS EXAMPLE (2) In this example create an embedded style sheet containing four styles. 12
  • 14. Fig. 4.3 | Embedded style sheet. EMBEDDED STYLE SHEETS EXAMPLE (2) OUTPUT 14
  • 15. EMBEDDED STYLE SHEETS EXAMPLE (2): EXPLAINING LINE 11 TO 18 Line 11: Styles placed in the head apply to matching elements wherever they appear in the body. The style element’s type attribute specifies the MIME (Multi purpose Internet Mail Extensions) type that describes the style element’s content. lines 12–17: declares the CSS rules for the style sheet. 15 Default in HTML 5
  • 16. STYLE SHEETS SYNTAX  A style sheet consists of a set of rules.  Each rule consists of one or more selectors and a declaration block.  Selectors are separated by commas  Declarations are separated by semicolons  Properties and values are separated by colons 16 h1,h2,h3 { color: green; font-weight: bold; }
  • 17. WRITING CSS CODE IN SEPARATE FILES CSS code can be written in its own files to keep it separate from the HTML code. The extension for CSS files is .css. These can be linked to an HTML file using a <link> tag in the <head> section. That called as External Style (highly recommended ) CSS rules in separate file .css extension linked via <link rel="stylesheet" href=…> tag 17
  • 18. WRITING CSS CODE IN SEPARATE FILES <LINK> TAG To link an external style sheet in html documents we use <link> tag. Note: Link tag is void. (No need to close it) o link tag has many elements some of them are: 18 Element (Attribut e) Description rel specify a relationship between two documents type specifies the MIME type of the related document href provides the URL for the document
  • 19. WRITING CSS CODE IN SEPARATE FILES  External style sheets are separate documents that contain only CSS rules.  Help create a uniform look for a website: oSeparate pages can all use the same styles. oModifying a single style-sheet file makes changes to styles across an entire website (or to a portion of one).  When changes to the styles are required, you need to modify only a single CSS file to make style changes across all the pages that use those styles. This concept is sometimes known as skinning. 19
  • 20. body { background-color: #E6E6FA; color: #000000;} h2 { color: #003366; } LINKING EXTERNAL STYLE SHEETS Multiple web pages can associate with the same external style sheet file. 20 site.css index.html clients.html about.html Etc…
  • 21. WHAT IS THE PREFERRED WAY OF INCLUDING CSS WITHIN A PROJECT? HOW DO I KNOW WHEN TO USE INLINE STYLES, THE TAGS, OR A .CSS FILE? As a web developer you will eventually come across HTML documents which include CSS either inline with style attributes or within the <style> tags at the head of the document. Hence, it is important to be aware of all the various ways to include CSS in a project. That having been said, mashing HTML and CSS together is not a great habit to get into. As developers we want to “separate our concerns” because this usually creates codebases that are more flexible, readable, and maintainable. As such, keeping our CSS contained within a separate .css file is the preferred way of including CSS within most projects. 21
  • 22. SELECTORS IN CSS 1. CSS Type Selectors  used to match all elements of a given type or tag name  For example, in HTML, the tag for a paragraph element is <p>. The CSS syntax for selecting <p> elements is: p { ….. } 22
  • 23. SELECTORS IN CSS 2. CSS class selectors  it matches elements based on the contents of their class attribute. a . needs to be prepended. 23 For example, consider the following HTML: <p class="brand">Sole Shoe Company</p> The paragraph element in the example above has a class attribute within the <p> tag. The class attribute is set to "brand". To select this element using CSS, we could use the following CSS selector: .brand { }
  • 24. SELECTORS IN CSS 3. CSS ID selectorsIt matches elements based on the contents of their id attribute. The values of id attribute should be unique. 24 Explain: If an HTML element needs to be styled uniquely (no matter what classes are applied to the element), we can add an ID to the element to the tag: <h1 id="large-title"> ... </h1> Then, CSS can select HTML elements by their id attribute. To select an id element, CSS prepends the id name with a hashtag (#). For instance, if we wanted to select the HTML element in the example above, it would look like this: #large-title {
  • 25. SELECTORS IN CSS 4. Groups of CSS Selectors  Match multiple selectors to the same CSS rule, using a comma-separated list. In this example, the text for both h1 and h2 is set to red. Example: h1, h2 { color: red; } 25
  • 26. SELECTORS IN CSS 5. Chaining Selectors  that rule sets apply only to elements that match all criteria. Example: 26 /* Select h3 elements with the section-heading class */ h3.section-heading { color: blue; } /* Select elements with the section-heading and button class */ .section-heading .button { cursor: pointer; }
  • 27. MULTIPLE CLASSES For instance, perhaps there’s a heading element that needs to be green and bold. You could write two CSS rules like so: .green { color: green; } .bold { font-weight: bold; } Then, you could include both of these classes on one HTML element like this: <h1 class="green bold"> ... </h1> We can add multiple classes to an HTML element’s class attribute by separating them with a space. This enables us to mix and match CSS classes to create many unique styles without writing a custom class for every style combination needed. 27
  • 28. CLASS VS ID classes are meant to be used many times ID is meant to style only one element. IDs override the styles of tags and classes. ID attribute should be unique 28
  • 29. SELECTOR SPECIFICITY The most specific selector type is the ID selector, followed by class selectors, followed by type selectors. In this example, only color: blue will be implemented as it has an ID selector whereas color: red has a type selector Specificity is a ranking system that is used when there are multiple conflicting property values that point to the same element. When determining which rule to apply, the selector with the highest specificity wins out. 29 h1 #header { color: blue; } /*implemented*/ h1 { color: red; } /*not implemented*/
  • 30. CSS !IMPORTANT RULE The CSS !important rule is used on declarations to override any other declarations for a property and ignore selector specificity. !important rules will ensure that a specific declaration always applies to the matched elements. However, generally it is good to avoid using !important as bad practice. 30 #column-one { width: 200px !important; } .post-title { color: blue !important; }
  • 31. Review CSS Selectors •CSS can change the look of HTML elements. In order to do this, CSS must select HTML elements. •CSS can select HTML elements by tag, class, or ID. •Multiple CSS classes can be applied to one HTML element. •Classes can be reusable, while IDs can only be used once. •IDs are more specific than classes, and classes are more specific than tags. •The !important flag will override any style, however it should almost never be used, as it is extremely difficult to override. •Multiple unrelated selectors can receive the same styles by separating the selector names with commas. 31
  • 32. SOME OF CSS FONT PROPERTY font-family Property font-family property specifies the name of the font to use. 32 Fig. 4.5 | Generic font families.
  • 33. SOME OF CSS FONT PROPERTY font-size Property  font-size property: specifies the size used to render the font.  You can specify a point size such(12pt) or a relative value such as (xx- small, x-small, small, smaller, medium, large, larger, x-large and xx- large).  Relative font-size values are preferred over points, because an author does not know the specific measurements of each client’s display.  Relative values permit more flexible viewing of web pages.  For example, users can change font sizes the browser displays for readability. 33
  • 34. SOME OF CSS FONT PROPERTY font-weight property  font-weight property : specifies the “boldness” of text. Possible values are: o bold o normal (the default) o bolder (bolder than bold text) o lighter (lighter than normal text) 34
  • 35. SOME OF CSS FONT PROPERTY text-align property  The text-align property places text in the left, right, or center of its parent container. color property :  defines the color of the text. 35
  • 36. VALUES IN THE CSS RULES  Colors are set in RGB format (decimal or hex): o Example: #a0a6aa = rgb(160, 166, 170) o Predefined color aliases exist: black, blue, etc.  Numeric values are specified in: o Pixels, ems, e.g. 12px , 1em o Points, inches, centimeters, millimeters • E.g. 10pt , 1in, 1cm, 1mm o Percentages, e.g. 50% o Zero can be used with no unit: border: 0; 36