Full Stack Development - 22CS2305: Module 2 - Css3
Full Stack Development - 22CS2305: Module 2 - Css3
MODULE 2 – CSS3
Prof. Suvika K V,
Assistant Professor,
Dept. of CSE
2
Theory - Modules
2 2 CSS3
3 3 JavaScript
4 4 Node JS
5 5 Express.JS
3
Module 2 - CSS3
Topics
1. Levels of style sheets
2. Style specification formats
3. Selector forms
4. Property value forms
5. Font properties
6. List properties
7. Color
8. Alignment of text
9. Background images
10. Conflict Resolution
11. CSS Box Model
12. CSS3 features: Box Shadow, Opacity, Rounded corners, Attribute selector
4
➢ CSS describes how HTML elements are to be displayed on screen, paper, or in other media.
➢ CSS can control the layout of multiple web pages all at once.
➢ CSS is used to define styles for your web pages, including the design, layout and variations in
➢ Saves time
➢ Easy to change
➢ The Cascading Style Sheets is defined at three different levels to specify the style of a Document.
➢ Lower level style sheets can override higher level style sheets , so the style of the content of a tag is
determined ,in effect ,through a cascade of style sheet applications.
➢ Inline style sheets have precedence over document style sheets ,which have precedence over external
style sheets.
Inline
Document/
Levels in CSS
Internal
External
7
i. Inline Styles
➢ Inline style specifications appear within the opening tag and apply only to the content
of that tag.
8
➢ Document level style specifications appear in the document head section and apply to
➢ External Style sheets can apply to the bodies of any number of documents.
➢ External Style sheets stored separately and are referenced in all documents that use them
➢ External style sheets are written as text files with the MIME type text/css.
➢ Document-Level (Internal) Style Sheets: These are specified in the <head> of a document,
➢ External Style Sheets: These are specified in a separate CSS file that is connected to the HTML
Syntax
Syntax
•h1 is a selector in CSS (it points to the HTML element you want to style: <h1>).
<body>
<h1> Silent Film Pioneers </h1>
<p> India's first silent feature film, "Raja Harishchandra," was released in 1913 by Dadasaheb Phalke, often regarded as the father of Indian
cinema. </p>
</body>
</html>
23
➢ Inline style specifications appear as values of the style attribute of a tag,4 the general form of
which is as follows:
➢ Document style specifications appear as the content of a style element within the header of a
document, although the format of the specification is quite different from that of inline style sheets.
The general form of the content of a style element is as follows:
25
➢ External style: Each style rule in a rule list has two parts: a selector, which indicates the
element or elements affected by the rule, and a list of property-value pairs. The list has the
same form as the quoted list for inline style sheets, except that it is delimited by braces rather than
double quotes. So, the form of a style rule is as follows:
26
3. Selector Forms
➢ A selector specifies the elements to which the following style information applies.
Simple
Selector
Forms
Universal Class
Selector Selectors
Selector
Pseudo
Forms
Generic
Classes Selectors
Contextual id
Selectors Selectors
27
➢ Here, the property values in the rule apply to all occurrences of the named element.
➢ The selector could be a list of element names separated by commas, in which case the property
values apply to all occurrences of all of the named elements.
➢ The first of these selector forms specifies that the following property-value list applies to all h1
elements.
➢ The second specifies that the following property-value list applies to all h2 and h3 elements
28
➢ Class selectors are used to allow different occurrences of the same tag to use different
style specifications.
➢ A style class is defined in a style element by giving the style class a name, which is attached to the
tag’s name with a period.
➢ For example, if you want two paragraph styles in a document—say, normal and warning—you could
define these two classes in the content of a style element as follows:
Class Selectors
➢ Within the document body, the particular style class that you want is specified with the class
attribute of the affected tag.
32
➢ It is convenient to have a class of style specifications that applies to the content of more than one
kind of tag.
➢ Without the tag name, the name of the generic class begins with a period.
35
iv. id Selectors
➢ An id selector allows the application of a style to one specific element. The general form of an id
selector is as follows:
➢ the style specified in the id selector applies to the element with the given id.
id Selectors - Code
<!DOCTYPE html>
<html>
<head>
<title>Simple Selector</title>
<style type="text/css">
#one{font-family: Monotype Corsiva; font-size : 50pt ; color : red ; text-align : center;}
#two{font-family: Monotype Corsiva; font-size : 30pt ; color : blue ; text-align : left;}
</style> </head>
<body>
<h1 id="one"> My Favourite Anime </h1>
<p id="two"> Naruto is my favourite </p>
</body>
</html>
39
v. Contextual Selectors
➢ A contextual selector is defined as a selector which considers the context where the style is to be
applied.
➢ In simple words, the specified style is applied to an element only if the element is in the specified
context.
➢ A contextual selector is made up of two or more simple selectors separated by white space.
<html>
<head>
<title>Contextual Selectors1</title>
<style type="text/css">
</style> </head>
<body>
<div>
<p>Module 1: HTML</p>
</div>
<p>Module 2: CSS</p>
</body>
</html>
42
<html>
<head>
<title>Contextual Selectors2</title>
<style type="text/css">
</style> </head>
<body>
<div>
<p>Module 1: HTML</p>
</div>
<p>Module 2: CSS</p>
</body>
</html>
44
<html>
<head>
<title>Contextual Selectors3</title>
<div>
<span><p>Module 2: CSS</p></span>
</div>
</body>
</html>
46
➢ Pseudo classes specify that certain styles apply when something happens, rather than because the
target element simply exists.
➢ Example: When mouse movement happens ,in other words hover happens or focus happens.
Pseudo Classes
Pseudo
Classes
Style
Style any
Hypertext
element
links
link hover
visited focus
52
➢ The link pseudo class is used to style a link that has not been selected.
➢ The visited pseudo class is used to style a link that previously has been selected.
➢ The style of the hover pseudo class applies when its associated element has the mouse cursor
over it.
➢ The style of the focus pseudo class applies when its associated element has focus. {active}
53
➢ The universal selector, denoted by an asterisk (*), applies its style to all elements in a document.
➢ For every element in a document to have a particular set of properties, we could include the
following:
56
➢ The most commonly used categories are: fonts, lists, alignment of text, margins, colors,
backgrounds, and borders.
59
font-size
➢ Keyword property values are used when there are only a few possible values and they are
➢ Keyword values are not case sensitive, so Small, SmAlL, and SMALL are all the same as small.
60
➢ Number values are used when no meaningful units can be attached to a numeric property
value.
➢ A number value can be either an integer or a sequence of digits with a decimal point and can
Length
➢ Length values are specified as number values that are followed immediately by a two-
➢ There can be no space between the number and the unit name.
➢ The possible unit names are px, for pixels; in, for inches; cm, for centimeters; mm, for
millimeters; pt, for points (a point is 1/72 inch); and pc, for picas, which are 12 points.
62
Relative Length
Percentage Values
➢ Percentage values are used to provide a measure that is relative to the previously used
➢ Percentage values are numbers that are followed immediately by a percent sign (%)
➢ Ex: Font size were set to 75% with a style sheet, it would make the new current size for the
➢ Percentage values can be signed. If preceded by a plus sign, the percentage is added to the
Color Property
➢ Color property values can be specified as color names, as six-digit hexadecimal numbers, or
in RGB form.
➢ RGB form is just the word rgb followed by a parenthesized list of three decimal numbers in
➢ These numbers or percentages specify the levels of red, green, and blue, respectively.
URL Property
➢ URL property values use a form that is slightly different from references to URLs in links.
➢ The actual URL, which can be either absolute or relative, is placed in parentheses and
preceded by url.
66
5. Font Properties
Font
Families
Text Font
Spacing Sizes
Text
Font Variants
Decoration
Font Font
Shorthands Styles
Font
Weights
67
i. Font Families
<!DOCTYPE html>
<html>
<head>
<title>Font Families</title>
<style type="text/css">
div p{font-family: 'Times New Roman';font-size: 30pt;}
p{font-family: monospace;font-size: 50pt;}
</style>
</head>
<body>
<p>National Award Winners</p>
<div>
<p>Rakshith Shetty</p>
<p>Allu Arjun</p>
</div>
<p>Kriti Sanon</p>
<p>Alia Bhatt</p>
</body>
</html>
69
➢ Absolute: the size value could be given as a length value in points, picas, or pixels, or as a keyword
from the list: xx-small, x-small, small, medium, large, x-large, and xx-large.
➢ Relative: The relative size values are smaller and larger, which adjust the font size relative to the
➢ Problem with the keyword sizes is that the size relationship between adjacent keywords is not
<!DOCTYPE html>
<html>
<head>
<title>Font Sizes</title>
<style type="text/css">
div p{font-family: 'Times New Roman';font-size: small;}
p{font-family: monospace;font-size: 50%;}
</style>
</head>
<body>
<p>National Award Winners</p>
<div>
<p>Rakshith Shetty</p>
<p>Allu Arjun</p>
</div>
<p>Kriti Sanon</p>
<p>Alia Bhatt</p>
</body>
</html>
72
➢ The default value of the font-variant property is normal, which specifies the usual
character font.
➢ These are all uppercase, but the letters that are normally uppercase are a bit larger than
font-style: italic
<!DOCTYPE html>
<html>
<head>
<title>Font Styles</title>
<style type="text/css">
h2{color: red; font-style: oblique;}
p{font-size: 30pt; font-style: italic;}
</style>
</head>
<body>
<h2>National Award Winners - MUSIC</h2>
<p>DEVI SRI PRASAD</p>
<p>KALA BHAIRAVA</p>
<p>SHREYA GHOSHAL</p>
</body>
</html>
78
v. Font Weights
</style>
</head>
<body>
<h1>2023 Awards</h1>
<h2>National Award Winners - MUSIC</h2>
<p>DEVI SRI PRASAD</p>
<p>KALA BHAIRAVA</p>
<p>SHREYA GHOSHAL</p>
</body>
</html>
81
➢ If more than one font property must be specified, the values can be stated in a list as the
➢ The browser then determines which properties to assign from the forms of the values.
➢ The above property specifies that the font weight should be bold, the font size
{second to last} should be 1.1 times that of its parent element, and either Times New
Roman or Palatino font name {last} should be used, with precedence given to Times
New Roman.
83
<!DOCTYPE html>
<html>
<head>
<title>Font Shorthands</title>
<style type="text/css">
h2{color: red;}
p{font: bolder 32px 'Open Sans', sans-serif;}
</style>
</head>
<body>
<h2>National Award Winners - MUSIC</h2>
<p>DEVI SRI PRASAD</p>
<p>KALA BHAIRAVA</p>
<p>SHREYA GHOSHAL</p>
</body>
</html>
84
text.
<!DOCTYPE html>
<html>
<head>
<title>Text Decoration</title>
<style type="text/css">
p.one{font-size: 50pt; color: red ; text-decoration: line-through;}
p.two{font-size: 30pt; color: green ; text-decoration: underline;}
p.three{font-size: 30pt; color: purple ; text-decoration: overline;}
</style>
</head>
<body>
<p class="one"> My Favourite Series </p>
<p class="two"> Friends </p>
<p class="three"> Breaking Bad </p>
</body>
</html>
87
Text Spacing
letter-spacing line-height
word-spacing
(Tracking) (Leading)
letter-spacing: -1px
word-spacing: -1px
Squeezes the
Squeezes the words
letters
89
</body>
</html>
90
6. List Properties
➢ Two presentation details of lists can be specified in HTML documents: the shape of the bullets
that precede the items in an unordered list and the sequencing values that precede the items in
an ordered list.
➢ If list-style-type is set for a ul or an ol tag, it applies to all of the list items in the list.
➢ The list-style-type property of an unordered list can be set to disc (the default), circle,
square, or none.
➢ A disc is a small filled circle, a circle is an unfilled circle, and a square is a filled square.
92
<!DOCTYPE html>
<html>
<head>
<title>Unordered List1</title>
<style type="text/css">
ul{font-size: 30pt; color: red;}
</style>
</head>
<body> By Default, disc – bullet is
<h1>Programming languages</h1>
<ul>
considered for unordered list
<li>C</li>
<li>C++</li>
<li>Java</li>
<li>Python</li>
</ul>
</body>
</html>
93
<!DOCTYPE html>
<html>
<head>
<title>Unordered List2</title>
<style type="text/css">
ul{font-size: 30pt; color: blue; list-style-type: square;}
</style>
</head>
<body>
<h1>Programming languages</h1>
<ul>
<li>C</li>
<li>C++</li>
<li>Java</li>
<li>Python</li> Here, list-style-type is square.
</ul>
</body>
</html>
95
<!DOCTYPE html>
<html>
<head>
<title>Unordered List3</title>
<style type="text/css">
ul{font-size: 30pt; color: blue; list-style-type: circle;}
</style>
</head>
<body>
<h1>Programming languages</h1>
<ul>
<li>C</li>
<li>C++</li>
<li>Java</li>
<li>Python</li> Here, list-style-type is circle.
</ul>
</body>
</html>
97
Ordered List
➢ The list-style-type property can be used to specify the types of sequence values.
103
<!DOCTYPE html>
<html>
<head>
<title>Ordered List1</title>
<style type="text/css">
ul{font-size: 30pt; color: red;}
</style>
</head>
<body> By Default, numbers from 1 is
<h1>Programming languages</h1>
<ol>
considered for ordered list
<li>C</li>
<li>C++</li>
<li>Java</li>
<li>Python</li>
</ol>
</body>
</html>
104
<!DOCTYPE html>
<html>
<head>
<title>Ordered List2</title>
<style type="text/css">
li{font-size: 30pt; color: blue; list-style-type: upper-alpha;}
</style>
</head>
<body>
<h1>Programming languages</h1>
<ol>
<li>C</li>
<li>C++</li>
<li>Java</li>
<li>Python</li>
</ol>
</body>
</html>
106
Exercise - Solution
7. Color
Color Groups
3 Groups
Web Palette –
17 Colors 147 Colors
216 Colors
110
Color Properties - Code
8. Alignment of Text
➢ The text-indent property can be used to indent the first line of a paragraph. This property takes
➢ The text-align property, most commonly used keyword values are left, center, right, and justify, is
➢ The float property is used to specify that text should flow around some element, often an image or a
table. The possible values for float are left, right, and none, which is the default.
113
Alignment of Text - Code
</body>
</html>
114
9. Background Images
➢ The background image is replicated as necessary to fill the area of the element. This replication is
called tiling.
➢ Tiling can be controlled with the background-repeat property, which can take the value repeat (the default),
➢ The no-repeat value specifies that just one copy of the image is to be displayed.
➢ The repeat-x value means that the image is to be repeated horizontally; repeat-y means that the image is to be
repeated vertically.
116
Background Images
➢ The position of a non repeated background image can be specified with the background-position property,
➢ The keyword values are top, center, bottom, left, and right, all of which can be used in combinations.
➢ It is easiest to use one keyword to specify the horizontal placement and one to specify the vertical placement,
➢ If only one keyword is given, the other is assumed to be center. So, top is equivalent to top center (or center
top), and left is the same as center left (or left center).
117
<body>
<h1>Dayananda Sagar University</h1>
<p class="one">Dayananda Sagar Institutions founded in the 60s by one such visionary, late Sri
Dayananda Sagar committed to take knowledge to the people, transforms today’s students into responsible
citizens and professional leaders of tomorrow.</p>
</body>
</html>
122
<span>
➢ In many situations , we want to apply special font properties to less than a whole paragraph of text
may be for a single word.
<span> - Code
<!DOCTYPE html>
<html>
<head>
<title>Span</title>
<style type="text/css">
p{font-size: 20pt;}
.one{font-size: 30pt; color: red;}
</style>
</head>
<body>
<p> My favourite subject is <span class="one">FSD</span></p>
</body>
</html>
125
<div>
➢ We can apply a style to a section of document rather than to each paragraph . This can be done with
the <div> tag.
<div> - Code
<!DOCTYPE html>
<html>
<head>
<title>Div</title>
<style type="text/css">
.one{font-size: 30pt; color: red;}
.two{font-size: 25pt; color: blue;}
</style>
</head>
<body>
<div class="one">
<p> My favourite subject is FSD</p>
<p> My favourite module is CSS</p>
</div>
<div class="two">
<p> My favourite subject is FSD</p>
<p> My favourite module is CSS</p>
</div>
</body>
</html>
128
1. When style sheets at 2 or more levels specify different value for same property on some element.
➢ The inline level gets the highest priority over the document level.
➢ The document level gets the higher priority over the external level.
130
Conflict Resolution
2. A property value conflict may occur within a single style sheet. Consider the following style specifications,
which are next to each other in the same document-level style sheet:
• h3 {color: blue;}
➢ Both these specifications apply to all h3 elements in the body of the document.
Conflict Resolution
3. Another source of conflict can arise from the fact that there can be several different origins of the
➢ For example, they may come from a style sheet written by the author of the document itself but they may
Conflict Resolution
The property value specifications can be marked as being important by including !important in the
Conflict Resolution
Step 1: Gather information about levels of style sheet. All the origins and weights are sorted. The following
Conflict Resolution
Step 2: If there are other conflicts even after sorting ,The next step is sorting by specificity. Rules are:
1. id selectors
2. Class and pseudo class selectors
3. Contextual selectors (more element type names means that they are more specific)
4. Universal selectors
➢ If there still conflicts, they are resolved by giving precedence to most recently seen specification.
• The whole sorting process that is used to resolve style specification conflicts is called the cascade.
135
Conflict Resolution
➢ Inheritance is another source of property-value conflicts; although as we already know, the inherited
property value is always overridden by the property value given to the descendant element.
➢ A child element always inherits the styles of the parent element, unless declared otherwise separately. Even
<!DOCTYPE html>
<html>
<head>
<title>Inheritance</title>
<style type="text/css">
.one{font-size: 30pt; color: red;}
.two{font-size: 25pt; color: blue;}
.three{font-size: 25pt; color: hotpink;}
</style>
</head>
<body>
<p class="one">
<p class="two"> My favourite subject is FSD</p>
</p>
<p class="one">
<p class="two three"> My favourite subject is FSD</p>
</p>
</body>
</html>
137
➢ Virtually all document elements can have borders with various styles, such as color and width.
➢ The amount of space between the content of an element and its border, known as padding, can be
specified, as well as the space between the border and an adjacent element, known as the margin.
This model, called the box model.
Borders
Borders
The shorthand for setting the style properties of all four borders of an element, border.
The cells of a table can have borders, like any other element:
Borders - Code
➢ Padding is the space between the content of an element and its border.
➢ Margin is the space between the border of an element and the element’s neighbors.
➢ When there is no border, the margin plus the padding is the space between the content of an element and its
neighbors.
➢ There is a difference when the element has a background: The background extends into the padding, but not
into the margin.
</head> </body>
</html>
145
Value Description
None Default value, No shadow is displayed
H-offset The horizontal offset of the shadow. A positive value puts the shadow on the
right side of a Box. A negative value puts the shadow on left side of the box.
V-offset The vertical offset of the shadow. A positive value puts the shadow below
the box. A negative value puts the shadow above the box.
Blur Optional. The blur radius ,the higher the number ,the more blurred the
shadow will be.
Color The color of the shadow, the default value is text color.
147
<!DOCTYPE html>
<html>
<head>
<style>
#ex1{border: 1px solid; padding: 10px; box-shadow: 5px 10px 8px blue;}
#ex2{border: 1px solid; padding: 10px; box-shadow: -5px -10px 28px red;}
</style>
</head>
<body>
</body>
</html>
148
➢ Opacity value can take a value from 0.0 -1.0. The lower value, the more transparent.
150
<body>
<h1> Image Transparency </h1>
<p> Image with NO opacity </p>
<img src="one.png" alt="One" width="200" height="150">
</body>
</html>
151
➢ With the CSS border-radius property, we can give any element “Rounded Corners”.
155
<!DOCTYPE html>
<html>
<head>
<title> Rounded Corners </title>
<style>
#rcorners1{border-radius: 25px; padding: 20px; background: #73AD21; width: 200px; height: 150px;}
#rcorners2{border-radius: 45px; padding: 20px; border: 2px solid #73AD21; width: 200px; height: 150px;}
#rcorners3 {border-radius: 25px; padding: 20px; background: url(one.png); background-position: left top;
width: 200px; height: 150px;}
</style>
</head>
156
<body>
<h1>The border-radius Property</h1>
<p>Rounded corners for an element with a specified background color:</p>
<p id="rcorners1">Rounded corners!</p>
<p>Rounded corners for an element with a border:</p>
<p id="rcorners2">Rounded corners!</p>
<p>Rounded corners for an element with a background image:</p>
<p id="rcorners3">Rounded corners!</p>
</body>
</html>
157
It is possible to Style HTML elements that have specific Attributes or Attribute values.
Ex: The following example selects all <a> elements with a target attribute
a[target]{
background-color :yellow;
}
159
THANK YOU