17CS71 Wta Mod 1 PPT
17CS71 Wta Mod 1 PPT
io
INSTAGRAM: www.instagram.com/hemanthraj_hemu/
INSTAGRAM: www.instagram.com/futurevisionbie/
DEPARTMENT OF CSE
By,
Prof.Muneshwara M S Prof. Shankar R
https://hemanthrajhemu.github.io 014
om
Objectives
1 HTMLDefinedandits
History 2 HTMLSyntax
3 Semantic Markup
4 StructureofHTML
5 QuickTour of HTML
6 HTML
SemanticElements
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Brief History ofHTML
Did we mention that this will be brief?
https://hemanthrajhemu.github.io
HTML Syntax
What is a markup language?
https://hemanthrajhemu.github.io
Markup
What is itagain?
https://hemanthrajhemu.github.io
What is the W 3 C ?
Standards
https://hemanthrajhemu.github.io
XHTML
Partying like it’s1999
https://hemanthrajhemu.github.io
XHTML
You too can be strict
https://hemanthrajhemu.github.io
XHTML
Two versions
https://hemanthrajhemu.github.io
Standards Movement
Following a standard is a good thing
https://hemanthrajhemu.github.io
Validators
How to ensure your pages follow a standard
https://hemanthrajhemu.github.io
How about an example
Only if you have an internet connection
https://hemanthrajhemu.github.io
XHTML 2.0 and WHATWG
Where did it go?
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
HTML5
The new hotness
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
HTML5
Three main aims
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
HTML5
It evolves
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
HTML5 Support in Browsers
NoHTML5
Support
Partial HTML5Support
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Section2of6
H T M L SYNTAX
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Elements and Attributes
More syntax
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
What HTML lets you do
Trailing Slash
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Nesting HTML elements
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Hierarchy of elements
ancestor
<body> parent
child
<p>
This i s some <strong>text</strong>
</p>
<h1>Title goes here</h1>
sibling
<di v>descendants
<p>
This i s <span>important</span>
</p>
</ di v>
</body>
<body>
descendants children
<span>
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Nesting HTML elements
Incorrect Nesting
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Section3of6
SEMANTIC MARKUP
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Semantic Markup
What does itmean?
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Semantic Markup
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Structure
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Semantic Markup
Its advantages
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Section4of6
STRUCTURE O F H T M L
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Simplest HTML document
1 <!DOCTYPE html>
< t i t l e > A Very Small Document</title>
<p>This i s a simple document with not much content</p>
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
A more complete document
1 <!DOCTYPE html>
<html>
2 <head lang="en">
<meta c hars et="utf - 8" > 5
3 <title>Share Your Travels - - New York - Central P a r k < / t i t l e >
< l i n k r e l = " s t y l e s h e e t " href="css/main.css"> 6
<script src="js/html5shiv.js"></script> 7
</head>
<body>
<h1>Main heading goes here</h1>
4 ...
</body>
</html>
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
1 DOCTYPE
(short for Document Type Definition)
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
HTML, Head, and Body
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Head and Body
HTML pages are divided into two sections: thehead
and the body, which correspond tothe <head> and
<body> elements.
3 The head contains descriptive elements about the
document
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Inside the head
There are no brains
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Inside the head
No brains but metas, styles and javascripts
6
Our example specifies an external CSSstyle sheet file
that is used with thisdocument.
7 It also references an external Javascriptfile.
1 <!DOCTYPE html>
<html>
2 <head lang="en">
<meta c h a r s e t = " u t f - 8 " > 5
3 < t i t l e > S h a re Your Travels - - New York - Ce n t ra l P a r k < / t i t l e >
< l i n k r e l = " s t y l e s h e e t " href ="css/main.css"> 6
<script src="js/html5shiv.js"></script> 7
</head>
<body>
<h1>Main heading goes here</h1>
4 ...
</body>
</html>
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Section5of6
Q U I C K TOUR O F H T M L
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Why a quick tour?
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Sample Document
<body>
<h1>Share Your Travels</h1>
1
<h2>New York - Cent r al Park</h2>
2 <p>Photo by Randy Connolly</p>
<p>This photo o f Conservatory Pond i n
<a hr ef =" ht t p: / / www. c ent r al par k . c om/ " >C ent r al Park</a> 3
New York C i t y was taken on October 22, 2011 w i t h a
<strong>Canon EOS30D</strong> camera.
</ p> 4
5 <img s r c = " i m a g e s / c e n t r a l - p a r k . j p g " a l t = " C e n t r a l Park" / >
<h3>Reviews</h3>
6 <div> 7
<p>By Ricardo on <time>September 15, 2012</time></p>
<p>Easy on t he HDRbuddy.</p>
</div>
<div>
<p>By Susan on <time>October 1 , 2012</time></p>
<p>I l ove Cent r al Park.</p>
</ di v>
8
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
1 Headings
<h1>, <h2>, <h3>, etc
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Headings
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Headings
Be semantically accurate
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
2 Paragraphs
<p>
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
6
Divisions
<div>
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Using div elements
Can you say “div-tastic”
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
3 Links
<a>
Destination Label(text)
Label (image)
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Types of Links
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Different link destinations
Link toexternal site
<a href ="http://ww w.c ent ra lpa rk .c om /logo. g if " >C entr a l Park</a>
<a href="index.html">Home</a>
Link to email
<a href="mailto://person@somewhere.com">Someone</a>
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Link Text
Some guidance … or … don’t “Click Here”
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
URL Absolute Referencing
For external resources
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
URL Relative Referencing
An essential skill
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
URL Relative Referencing
If all the resources for the site reside within the same
directory (also referred to as a folder), then you can
reference those other resources simply via their
filename.
However, most real-world sites contain too manyfiles
to put them all within a single directory.
For these situations, a relative pathname is required
along with the filename.
The pathname tells the browser where tolocate the
file on the server.
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Pathnames
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
URL Relative Referencing
Share-Your-Travels
Relative Link Type Example
/ (root folder)
1 Same Directory To link to example.html from
about.html (in Figure 2.18),use:
i ndex. ht ml
To link to a file within the same
<a href="example.html">
about.html folder, simply use the file name.
1 7
2 Child Directory To link to logo.gif from about.html,
example.html
use:
To link toa file within a subdirectory,
images/ <a h r e f =" images/ logo. gif" >
use the name of the subdirectory
2
logo.gif and a slash before the file name.
Grandchild/Descendant To link to background.gif from
cent r al - par k. j pg 3 Directory about.html, use:
css/ <a
To link to a file that is multiple
href="css/images/background.gif"
mai n. css subdirectories below the current
>
one, construct the full path by
images/
including each subdirectory name
3
background.gif (separated by slashes) before thefile
name.
members/
4 Parent/Ancestor Directory To link to about.html from
4 5
i ndex. ht ml
index.html in members, use:
Use “../” to reference a folder
<a h r e f = " . . / a b o u t . h t m l " >
randyc/ above the current one. If trying to
6
reference a file several levels above To link to about.html from
bio.html
the current one, simplystring bio.html, use:
together multiple “../”.
<a h r e f = " . . / . . / a b o u t . h t m l " >
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Images
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Images
Specifies the URL of the image to display Text in title attribute will be displayed in apopup
(note: uses standard relative referencing) tool tipwhen user moves mouse over image.
<img s r c = " i m a g e s / c e n t r a l - p a r k . j p g " a l t = " C e n t r a l Park " t i t l e = " C e n t r a l Park " width="80" height="40" / >
Text in alt attribute provides a brief Specifies the width and height of
description of image’s content for users who image in pixels.
are unable to seeit.
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Lists
<ol>
<li>Introduction</li>
<li>Back ground</li>
Notice that the list item element <li>My S o l u t i o n < / l i >
can contain other HTML <li>
elements <ol>
<li>Methodology</li>
<ul> <li>Results</li>
<li><a href="index.html">Home</a></li> <li>Discussion</li>
<li>About Us </li > </ol>
<li>Products</li> </li>
<li>Contact Us </li> <li>C onc lus ion < / l i >
</ul> </ol>
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Character Entities
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Section6of6
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
XHTML versus HTML5
<body>
< di v id="header">
<body>
1 <header>
< di v i d= " l ogo -headi ngs " >
<header> 2
1 <hgr oup>
<hgroup>
...
... 2
</div>
</hgroup>
...
...
< di v i d = " t o p - n a v i g a t i o n " > <nav>
... ...
</div> </nav>
</ di v>
3 <nav> 3
4 < di v id="main"> </header>
<div id="main">
< di v i d = " l e f t - n a v i g a t i o n " >
<nav>
...
...
</div>
</nav>
< di v c l as s = " c ontent" > <section>
5 < di v c l a s s = " s t o r y" >
<section>
5 <article>
...
6 <article> ... 6
</div> </article>
< di v c l a s s = " s t o r y" >
<article>
... <figure>
< di v c l as s = " s tor y -p ho t o" >
<img . . . c l as s = " bl og -p ho t o" />
7 <img . . . / > 7
<f i gcapt i on>. . .
<p c l a s s s = " p h o t o - c a p t i o n " > . . . <figure>
</figure>
</div>
8 <figcaption> ...
</div>
</ ar t i cl e> 8
< di v c l a s s = " r e l a t e d - s t u f f - o n - r i g h t " > <asi de>
... 9 <aside> ... 9
</ di v> </ asi de>
</div> </ sect i on>
< di v c l as s = " c ontent" > <section>
... ...
</ di v> </section>
</div> </ di v>
10 < di v i d = " f o o t e r " > <footer>
...
10
...
<f oot er > </ di v> </ f oot er >
</ body> </ body>
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
1 10
Header and Footer
<header> <footer>
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Header and Footer
<header>
<img s r c = " l o g o . g i f " a l t = " l o g o " / >
<h1>Fundamentals o f WebDevelopment</h1>
...
</header>
<article>
<header>
<h2>HTML5 Semantic Str uc ture Elements </h2>
<p>By <em>Randy Connolly</em></p>
<p><time>September 30, 2012</time></p>
</header>
...
</article>
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
2
Heading Groups
<hgroup>
<header>
<hgroup>
<h1>Chapter Two: HTML1</h1>
<h2>An Introduction</h2>
</hgroup>
</header>
<article>
<hgroup>
<h2>HTML5 Semantic Str uc tur e Elements </h2>
<h3>Overview</h3>
</hgroup>
</article>
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
3 Navigation
<nav>
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Navigation
<header>
<img s r c = " l o g o . g i f " a l t = " l o g o " / >
<h1>Fundamentals o f WebDevelopment</h1>
<nav role="navigation">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About Us</a></li>
<li><a href="browse.html">Browse</a></li>
</ul>
</nav>
</header>
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
5 6
Articles and Sections
<article> <section>
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Articles and Sections
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Sections versus Divs
How to decide which to use
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
7 8
Figure and Figure Captions
<figure> <figcaption>
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Figure and Figure Captions
Note however …
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Figure and Figure Captions
<p>This photo was taken on October 22, 2011 with a Canon EOS30D camera.</p>
<figure>
<img s rc ="im ages /c entral -park .j pg" a l t = " C e n t r a l Park" /><br/>
Figure could be <figcaption>Conservatory Pond i n Central Park </figcaption>
moved to a </figure>
different <p>
location in I t was a wonderfully b e a u t i f u l autumn Sunday, with strong s u n l i g h t and
document expressive c louds . I was very f o r t u n a t e t h a t myone day i n New York was
…
blessed with such weather!
But it has to
</p>
exist in the
document
(i.e., the
figure isn’t
optional)
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
9
Aside
<aside>
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
WhatYou’ve Learned
1 HTMLDefinedandits
History 2 HTMLSyntax
3 Semantic Markup
4 StructureofHTML
5 QuickTour of HTML
6 HTML
SemanticElements
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
CSS 1: Introduction
Chapter 3
3 LocationofStyles
4 Selectors
5 TheCascade:How
Styles Interact 6 The BoxModel
7 CSSTextStyling
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Section1of7
WHAT IS CSS?
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
What is CSS?
You be styling soon
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
What is CSS?
You be styling soon
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Benefits of CSS
Why using CSS is a better way of describing presentation than HTML
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
CSS Versions
Let’s just say there’s more than 1
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Browser Adoption
Insert obligatory snide comment about Internet Explorer 6 here
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Section2of7
CSS SYNTAX
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
CSS Syntax
Rules, properties, values, declarations
syntax
s e l e c t o r { p r o p e r t y: va l u e ; property2: value2; } rule
declarationblock
selector
em{ c o l o r : r e d ; }
p{
margin: 5px 0 10px 0 ;
font-weight: bold;
f o n t - f a m i l y : A r i a l , H e l ve t i c a , s a n s - s e r i f ;
}
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Declaration Blocks
• Each declaration is
declarationblock
terminated with a
semicolon. selector
em{ c o l o r : r e d ; }
p{
margin: 5px 0 10px 0 ;
font-weight: bold;
f o n t - f a m i l y : A r i a l , H e l ve t i c a , s a n s - s e r i f ;
}
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Selectors
Which elements
syntax
thinking of selectorsis s e l e c t o r { p r o p e r t y: va l u e ; property2: value2; } rule
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Properties
Which style properties of the selected elements
syntax
defines over ahundred sel ect or { pr oper t y: val ue; pr oper t y2: val ue2; } rule
selector
em{ c o l o r : r e d ; }
p{
margin: 5px 0 10px 0 ;
font-weight: bold;
f o n t - f a m i l y : A r i a l , H e l ve t i c a , s a n s - s e r i f ;
}
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Properties
Common CSS properties
Property Type Property
Fonts font
font-family
font-size
font-style
font-
weight
@font-face
Text letter-spacing
line-height
text-align
text-decoration
text-indent
Color and background background
background-color
background-image
background-position
background-repeat
color
Borders border
border-color
border-width
border-style
border-top
border-top-color
border-top-
width etc
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Properties
Common CSS properties continued.
Property Type Property
Spacing padding
padding-bottom, padding-left, padding-right, padding-top
margin
margin-bottom, margin-left, margin-right, margin-top
Sizing height
max-
height
max-width
min-height
min-width
width
Layout bottom, left, right, top
clear
display
float
overflo
w
position
visibility
z-index
Lists list-style
list-style-
image list-
style-type
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Values
What style value for the properties
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Color Values
CSSsupports a variety of different ways of describingcolor
Method Description Example
Name Use one of 17 standard color names.CSS3 color: red;
has 140 standard names. color: hotpink; /* CSS3only */
RGB Uses three different numbers between 0 color: rgb(255,0,0);
and 255 to describe the Red, Green, and color: rgb(255,105,180);
Blue values for the color.
Hexadecimal Uses a six-digit hexadecimal number to color: #FF0000;
describe the red, green, and blue valueof color: #FF69B4;
the color; each of the three RGBvalues is
between 0 and FF(which is 255 in
decimal). Notice that the hexadecimal
number is preceded by a hash or pound
symbol (#).
RGBa Allows you to add an alpha,or color: rgb(255,0,0, 0.5);
transparency, value. This allows a
background color or image to “show
through” the color. Transparency is avalue
between 0.0 (fully transparent) and 1.0
(fully opaque).
HSL Allows you to specify a color usingHue color: hsl(0,100%,100%);
Saturation and Light values. This is color: hsl(330,59%,100%);
available only in CSS3. HSLA is also
available as well.
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Units of Measurement
There are multiple ways of specifying a unit of measurement in CSS
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Relative Units
Unit Description Type
px Pixel. In CSS2this is a relative measure, while in CSS3it is Relative (CSS2)
absolute (1/96 of aninch).
Absolute (CSS3)
em Equal to the computed value of the font-size propertyof Relative
the element on which it is used. When used for font sizes,
the em unit is in relation to the font size of the parent.
% A measure that is always relative to another value. The Relative
precise meaning of %varies depending upon which
property it is beingused.
ex A rarely used relative measure that expresses size in Relative
relation to the x-height of an element’sfont.
ch Another rarely used relative measure; this one expresses Relative
size in relation to the width of the zero ("0") character of
an element’s font. (CSS3only)
rem Stands for root em, which is the font size of the root Relative
element. Unlike em, which may be different for each
element, the rem is constant throughout thedocument. (CSS3only)
vw, vh Stands for viewport width and viewport height. Bothare Relative
percentage values (between 0 and 100) of the viewport
(browser window). This allows an item to change size (CSS3only)
when the viewport isresized.
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Absolute Units
Unit Description Type
in Inches Absolute
cm Centimeters Absolute
mm Millimeters Absolute
pt Points (equal to 1/72 of aninch) Absolute
pc Pica (equal to 1/6 of aninch) Absolute
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Comments in CSS
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Section3of7
LOCATION OF STYLES
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Actually there are three…
Different types of style sheet
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Style Locations
Author Created CSS style rules can be located in three different locations
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Inline Styles
Style rules placed within an HTML element via the style attribute
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Embedded Style Sheet
Style rules placed within the <style> element inside the <head> element
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
External Style Sheet
Style rules placed within a external text file with the .css extension
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Section4of7
SELECTORS
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Selectors
Things that make your life easier
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Element Selectors
Selects all instances of a given HTML element
declaration
declarationblock
selector
em{ c o l o r : r e d ; }
property value
p{
margin: 5px 0 10px 0 ;
font-weight: bold;
f o n t - f a m i l y : A r i a l , H e l ve t i c a , s a n s - s e r i f ;
}
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Grouped Selectors
Selecting multiple things
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Reset
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Class Selectors
Simultaneously target different HTML elements
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Class Selectors
<head>
<title>Share Your Travels < / t i t l e >
<style>
.first {
f o n t - s t yl e : i t a l i c ;
color: brown;
}
< / s t yl e >
</head>
<body>
<h1 class="first">Reviews</h1>
<div>
<p class="first">By Ricardo on <time>September 15, 2012</time></p>
<p>Easy on the HDRbuddy.</p>
</div>
<hr/>
<div>
<p class="first">By Susan on <time>October 1 , 2012</time></p>
<p>I love Central Park.</p>
</div>
<hr/>
</body>
.first {
font-style: i t a l i c ;
c o l o r : brown;
}
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Id Selectors
Target a specific element by its id attribute
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Id Selectors
<head lang="en">
<meta c hars et="utf - 8">
<title>Share Your Travels - - New York - Central P a r k < / t i t l e >
<style>
#latestComment {
f o n t - s t yl e : i t a l i c ;
color: brown;
}
< / s t yl e >
</head>
<body>
<h1>Reviews</h1>
<div id="latestComment">
<p>By Ricardo on <time>September 15, 2012</time></p>
<p>Easy on the HDRbuddy.</p>
</div>
<hr/>
<div>
<p>By Susan on <time>October 1 , 2012</time></p>
<p>I love Central Park.</p>
</div>
<hr/>
</body>
#latestComment {
font-style: i t a l i c ;
c o l o r : brown;
}
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Id versus Class Selectors
How to decide
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Attribute Selectors
Selecting via presence of element attribute or by the value of an attribute
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Attribute Selectors
[title] {
cursor: help;
padding-bottom: 3px;
border-bottom: 2px dotted blue;
<head lang="en">
text-decoration: none;
<meta c h a r s e t = " ut f - 8" >
}
< t i t le> Shar e Your T r a v e l s < / t i t l e >
<style>
[title] {
cursor: help;
padding-bottom: 3px;
border-bottom: 2px dotted blue;
text-decoration: none;
}
< / s t yl e >
</head>
<body>
<div>
<img src="images/flags/CA.png" title="Canada Flag" / >
<h2><a href="countries.php?id=CA" t i t l e = " s e e posts from Canada">
Canada</a>
</h2>
<p>Canada i s a North American country c o n s i s t in g o f … </p>
<div>
<img src="images/square/6114907897.jpg" t i t l e = " A t top of Sulpher Mountain">
<img src="images/square/6592317633.jpg" title="Grace Presbyterian Church">
<img src="images/square/6592914823.jpg" title="Calgary Downtown">
</div>
</div>
</body>
17CS71-WEB TECHNOLOGYhttps://hemanthrajhemu.github.io
Fundamentals of Web Development
Pseudo Selectors
Select something that does not exist explicitly as an element
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Pseudo Selectors
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Contextual Selectors
Select elements based on their ancestors, descendants, or siblings
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Contextual Selectors
Selector Matches Example
Descendant A specified element that is div p
contained somewhere within
Selects a <p> element that is contained somewhere
another specified element
within a <div> element. That is, the <p> can be any
descendant, not just achild.
Child A specified element that is a div>h2
direct child of thespecified
Selects an <h2> element that is a child of a <div>
element
element.
Adjacent A specified element that is the h3+p
Sibling next sibling (i.e., comesdirectly
Selects the first <p> after any <h3>.
after) of the specifiedelement.
GeneralSibling A specified element that shares h3~p
the same parent as the specified
Selects all the <p> elements that share thesame parent
element.
as the <h3>.
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Descendant Selector
Selects all elements that are contained within another element
div p { …} #main d i v p : f i r s t - c h i l d { … }
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Contextual Selectors in Action
<body>
<nav>
<ul >
< l i > <a href="#">Canada</a></li>
< l i > <a href="#">Germany</a></li>
u l a : l i n k { c o l o r: blue; } < l i > <a href="#">United S t a t e s < / a > < / l i >
#main time { c o l o r : r e d ; }
</ul>
</nav>
<div id="main">
Comments as o f <time>November 15, 2012</time>
<div>
#main>time { c o l o r : p u r p l e ; } <p>By Ricardo on <time>September 15, 2012</time></p>
<p>Easy on the HDRbuddy.</p>
< / d i v>
<hr/>
<div>
#main d i v p : f i r s t - c h i l d { <p>By Susan on <time>October 1 , 2012</time></p>
c o l o r : green ; <p>I l o ve C e n t ra l Park.</p>
} </ di v>
<hr/>
< / d i v>
<footer>
<ul>
< l i > <a href="#">Home</a> | < / l i >
< l i > <a href="#">Browse</a> | < / l i >
</ul>
</footer>
</body>
Because
• there are three different types of style sheets
(author-created, user-defined, and the default
browser style sheet),
• author-created stylesheets can define multiple rules
for the same HTMLelement,
CSShas a system to help the browser determine how
to display elements when different style rulesconflict.
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Cascade
How conflicting rules are handled in CSS
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Cascade Principles
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Inheritance
Cascade Principle #1
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Inheritance
body {
font-family: Arial; inherited
<ht ml > color: red; inherited
b o r d e r : 8pt s o l i d green; not inherited
margin: 100px; not inherited
}
<head> <body>
<meta> < t i t l e > <h1> <h2> <p> <i mg> <h3> <di v> <di v> <p>
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Inheritance
How to force inheritance
<h3>Reviews</h3>
<div>
<p>By Ricardo on <time>September 1 5 , 2012</time></p>
<p>Easy on t h e HDRbuddy.</p>
</div>
<hr/>
<div>
<p>By Susan on <time>October 1 , 2012</time></p>
<p>I l o ve C e n t ra l Park.</p>
</div>
<hr/>
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Inheritance
<ht ml > div {
font-weight: bold; inherited
m argin: 50px; not inherited
b o r d e r : 1 p t s o l i d green; not inherited
<head> <body> }
<met a> <t i t l e> <h1> <h2> <p> <i mg> <h3> <di v> <di v> <p>
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Specificity
Cascade Principle #2
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Specificity
How it works
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Specificity
These color and font-weight
body { This t e x t i s not w i t h i n a p element.
properties are inheritable and thus font-weight: bold; <p>Reviews</p>
potentially applicable to all the child c o l o r : red; <div>
elements contained within thebody. } <p>By Ricardo on <time>September 15, 2012</time
<p>Easy on the HDRbuddy.</p>
However, because the <div> and <p> div { This t e x t i s not w i t h i n a p element.
elements also have the same f o n t - w e i g h t : normal; </ di v>
properties set, they override thevalue c o l o r : magenta; <hr/>
}
defined for the <body> element
<di v>
because their selectors (div and p) are p { <p>By Susan on <time>October 1 , 2012</time></p>
more specific. c o l o r : green; <p>I love Central Park.</p>
} </ di v>
Class selectors are more specific <hr/>
.last {
than element selectors, andthus c o l o r: blue; <di v>
take precedence and override } <p class="last">B y Dave on <time>October 15, 20
element selectors. <p c l a s s = " l a s t " id="verylast" >Thanks f o r p o s t i n
# ve ryl a s t { </ di v>
c o l o r : orange; <hr/>
f o n t - s i z e : 16pt;
}
Id selectors are more specificthan
class selectors, and thus take
precedence and override class
selectors.
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Specificity Algorithm Specificity Value
div {
element selector c o l o r : green; 0001
}
1 d i v form {
descendant selector overrides c o l o r : orange; 0002
}
(elements only)
3
#firstExample {
id selector overrides 0100
c o l o r : magenta;
}
4
overrides id + d i v #firstExample {
c o l o r : grey; 0101
additional }
selectors
A higher specificity value
overrides lower specificity
values
inline style 5
overrides <div s t y l e = " c o l o r : red; "> 1000
attribute
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Location
Cascade Principle #3
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Location
Browser’s
default style
settings
2 <head>
overrides <link rel="stylesheet" href="stylesA.css" /> 3
< l i n k r e l = " s t y l e s h e e t " href="stylesWW.css" / > overrides
4 <st yl e>
overrides
#example {
c o l o r : orange; 5 #example {
c o l o r : magenta; overrides color: blue;
}
}
</ st yl e>
</head>
<body> 6 overrides
<p id="example" s t y l e = " c o l o r : r e d ; " >
sample t e x t
</p>
</ body>
Can you guess what will be the color of the sample text?
17CS71-WEB TECHNOLOGYhttps://hemanthrajhemu.github.io
Fundamentals of Web Development
Location
What color would the sample text be if there wasn’t an inline style definition?
Browser’s
default style
settings
2 <head>
overrides <link rel="stylesheet" href="stylesA.css" /> 3
< l i n k r e l = " s t y l e s h e e t " href="stylesWW.css" / > overrides
4 <st yl e>
overrides
#example {
c o l o r : orange; 5 #example {
c o l o r : magenta; overrides color: blue;
}
}
</ st yl e>
</head>
<body> 6 overrides
<p id="example" s t y l e = " c o l o r : r e d ; " >
sample t e x t
</ p>
</ body>
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Location
There’s always an exception
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Section6of7
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
The Box Model
margin
border
padding
width
hei ght
background-color/background-image of element’sparent
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Background
Box Model Property #1
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Background Properties
Property Description
background A combined short-hand property that allows you to set the background values
in one property. While you can omit properties with the short-hand, do
remember that any omitted properties will be set to their default value.
background-attachment Specifies whether the background image scrolls with the document (default) or
remains fixed. Possible values are: fixed, scroll.
background-image Specifies the background image (which is generally a jpeg, gif, or png file)for
the element. Note that the URL is relative to the CSSfile and not the HTML.
CSS3introduced the ability tospecify multiple background images.
background-position Specifies where on the element the background image will be placed. Some
possible values include: bottom, center, left, and right. You can also supply a
pixel or percentage numeric position value as well. When supplying a numeric
value, you must supply a horizontal/vertical pair; this value indicates its
distance from the top left corner of the element.
background-repeat Determines whether the background image will be repeated. This is acommon
technique for creating a tiled background (it is in fact the default behavior).
Possible values are: repeat, repeat-x, repeat-y, and no-repeat.
background-size New to CSS3,this property lets you modify the size of the background image.
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Background Repeat
background-image: u r l ( . . / i m a g e s / b a c k g r o u n d s / b o d y - b a c k g r o u n d - t i l e . g i f ) ;
background-repeat: r e p e a t ;
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Background Position
50px
300px
body {
background: whit e u r l ( . . / i m a g e s / b a c k g r o u n d s / b o d y - b a c k g r o u n d - t i l e . g i f ) no - r epeat ;
bac k gr ound - pos it ion: 300px 50px;
}
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Borders
Box Model Property #2
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Borders
Property Description
border A combined short-hand property that allows you to set the style,
width, and color of a border in one property. The orderis important
and must be:
border-style border-width border-color
border-style Specifies the line type of the border. Possible values are: solid,
dotted, dashed, double, groove, ridge, inset, and outset.
border-width The width of the border in a unit (but not percents). A variety of
keywords (thin, medium, etc) are alsosupported.
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Shortcut notation
TRBL
When using this multiple values shortcut, they are applied in clockwise order starting at the top.
Thus the order is: top right bottomleft.
TRBL (Trouble)
top
b o r d e r - c o l o r : top r i g h t bottom l e f t ;
left right
b o r d e r - c o l o r : red green orange b l u e ;
bottom
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Margins and Padding
Box Model Properties #3 and #4
p {
border: s o l i d 1pt r e d ;
m argin: 0 ;
padding: 0 ;
}
p {
border: s o l i d 1pt r e d ;
m argin: 30px;
padding: 0 ;
}
p {
border: s o l i d 1pt r e d ;
m argin: 30px;
padding: 30px;
}
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Margins
Why they will cause you trouble.
p{
border: s o l i d 1pt r e d ;
margin: 0 ;
padding: 0 ;
}
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Collapsing Margins
<div>
<p>Every CSS r u l e . . . < / p >
<p>Every CSS r u l e . . . < / p >
1 90px
</ d iv>
50px <div>
<p>In CSS, the a d j o in i n g . . . </p>
<p>In CSS, the a d j o in i n g . . . </p>
50px 4 </ d iv>
50px
div {
2 90px b o rd e r: dotted 1pt green;
padding: 0 ;
50px margin: 90px 20px;
}
50px 5
p{
50px b o rd e r: s o l i d 1pt r e d ;
padding: 0 ;
3 90px margin: 50px 20px;
}
If overlapping margins did not collapse, then margin space for
would be 180p (90pixels for the bottom margin of the first<div> +
90 pixels for the top margin of the second <div>), while the
margins and for would be100px.
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Collapsing Margins
How it works
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Width and Height
Box Model Properties #5 and #6
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Width and Height
Potential Problem #1
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Width and Height
Potential Problem #2
Since the width and the height refer to the size of the
content area, by default, the total size of an element is
equal to not only its content area, but also to the sum
of its padding, borders, andmargins.
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
div {
b o x - s i z i n g : c o n t e n t -b o x;
w i d t h : 200px;
h e i g h t : 100px;
padding: 5px;
m argin: 10px;
b o r d e r : s o l i d 2pt b l a c k ; True element width = 10 + 2 + 5 + 200 + 5 + 2 + 10 = 234 px
} True element height = 10 + 2 + 5 + 100 + 5 + 2 + 10 = 134 px
div {
...
b o x - s i z i n g : b o r d e r -b o x; True element width = 10 + 200 + 10 = 220 px
}
True element height = 10 + 100 + 10 = 120 px
100px
f
p {
background-color: s i l v e r ;
}
} 100px
p {
background-color: s i l v e r ;
w i d t h : 200px;
h e i g h t : 100px;
}
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Overflow Property
o ve r f l o w: v i s i b l e ;
o v e r f l o w: hidden;
o ve r f l o w: s c r o l l ;
o ve r f l o w: a u t o ;
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Sizing Elements
Time to embrace ems and percentages
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
<body>
<div c l a s s = " p i x e l s " >
P i x e l s - 200px by 50 px
</div>
< s t y l e> 50% <div c las s="percent ">
html,body { Percent - 50% o f widt h and h e i g h t
m argin: 0; </div>
50% 50%
width:100%; </body>
height:100%;
background: s i l v e r ;
}
.pixels {
widt h: 200 px;
h e i g h t : 50 px ;
background: t e a l ;
} 50%
.percent {
width:50%;
height:50%; 50% 50%
background: o l i v e ;
}
<body>
. parent Fixed { <div c las s="parent Fixed">
widt h: 400 px; <strong>parent has f i x e d s ize</ s t rong>
h e i ght : 150 px ; <div c las s="percent">
background: b e i g e ; PERCENT - 50% o f widt h and h e i g h t
} </div>
. p a r e n t R e l a t iv e { 50% of parent (=200px) </div>
width:50%; <div c l a s s =" par ent Re lat iv e " >
height:50%; <strong>parent has r e l a t i v e s ize</ s t rong>
background: y e l l o w; <div c las s="percent">
} PERCENT - 50% o f widt h and h e i g h t
</style> </div>
</div>
50% 50% </body>
50% of parent
50%
https://hemanthrajhemu.github.io
50%
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Developer Tools
Chrome – Inspect Element Firefox –Inspect
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Section7of7
TEXT STYLING
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Text Properties
Two basic types
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Font-Family
A few issues here
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Specifying the Font-Family
1 Use this font as
the first choice
If it isn’t available, then
3 use this one
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Generic Font-Family
This monospace
In a monospace font,
each letter has the
same width
This
proportionally-spaced
font, each letter hasa
variable width
This cur si ve
This
Decorative and cursive fonts
f ant asy vary from system to system;
rarely used asa result.
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
@font-face
The future is now
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Font Sizes
M o control, mo problems
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
Font Sizes
Welcome ems and percents again
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
How to use ems and percents
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
How to use ems and percents
<body> Browser’s default text size is usually 16 pixels
<p> 100% or 1em is 16 pixels
<h3> 125% or 1.125em is 18 pixels
<h2>
150% or 1.5em is 24 pixels
<h1>
200% or 2em is 32 pixels
/ * using 16px s c al e * / <body>
<p>t hi s w i l l be about 16 p i xe l s < / p >
body { f o n t - s i z e : 100%; } <h1>this w i l l be about 32 pi xel s </ h1>
h3 { f o n t - s i z e : 1.125em; } / * 1.25 x 16 = 18 * / <h2>this w i l l be about 24 pi xel s </ h2>
h2 { f o n t - s i z e : 1.5em; } / * 1 . 5 x 16 = 24 * / <h3>this w i l l be about 18 pi xel s </ h3>
h1 { f o n t - s i z e : 2em; } / * 2 x 16 = 32 * / <p>this w i l l be about 16 p i xe l s < / p >
</body>
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
How to use ems and percents
It might seem easy … but it’s not …
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
ems and percents
<body>
<p>this i s 16 pi xel s </ p>
<h1>this i s 32 pixels</h1>
<article>
<h1>this i s 32 pixels</h1>
<p>this i s 16 pi xel s </ p>
<div>
<h1>this i s 32 pixels</h1>
<p>this i s 16 pixels </p>
</ di v>
</ ar t i cl e>
</body>
body { f o n t - s i z e : 100%; }
p { f o n t - s i z e : 1em; } / * 1 x 16 = 16px * /
h1 { f o n t - s i z e : 2em; } / * 2 x 16 = 32px * /
body { f o n t - s i z e : 100%; }
p { f o n t - s i z e : 1em; }
h1 { f o n t - s i z e : 2em; }
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
The rem unit
Solution to font sizing hassles?
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
The rem unit
/ * using 16px s c a l e * /
body { f o n t - s i z e : 100%; }
p {
f o n t - s i z e : 16px; / * f o r o l d e r browsers: w o n ’t s c a l e p r o p e r l y though * /
f o n t - s i z e : 1rem; / * f o r new browsers: s c a le s and simple t o o * /
}
h1 { f o n t - s i z e : 2em; }
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development
What you’ve learned
1 Whatis CSS?
2 CSS Syntax
3 LocationofStyles
4 Selectors
5 TheCascade:How
Styles Interact 6 The BoxModel
7 CSSTextStyling
https://hemanthrajhemu.github.io
17CS71-WEB TECHNOLOGY Fundamentals of Web Development