3_CSS
3_CSS
Introduction
• Cascading Style Sheets (CSS) is a style sheet language used for describing the look and
formatting of a document written in a markup language.
• It is a highly effective HTML tool that provides easy control over layout and presentation of website
pages by separating content from design.
• Typical CSS file is a text file with an extension .css and contains a series of commands or rules.
Introduction
CSS
CSS Benefits
• Easy to learn
• Linked via <link rel="stylesheet" href=…> tag or @import directive in embedded CSS block
• An inline style may be used to apply a unique style for a single element.
• An inline style loses many of the advantages of a style sheet (by mixing content with
presentation). Use this method sparingly!
• To use inline styles, add the style attribute to the relevant tag.
• An internal style sheet may be used if one single page has a unique style.
• Internal styles are defined within the <style> element, inside the head section of an HTML
page
• The <style> tag is used to define style information for an HTML document.
• Inside the <style> element you specify how HTML elements should render in a browser.
<head>
<style>
body {
background-color: linen;
}
h1 {
color: maroon;
margin-left: 40px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
• With an external style sheet, you can change the look of an entire website by changing just
one file.
• Each page must include a reference to the external style sheet file inside the <link> element.
The <link> element goes inside the head section
• An external style sheet can be written in any text editor. The file should not contain any html tags.
• The <link> tag defines a link between a document and an external resource.
rel
• Specifies the relationship between the current document and the linked document
type
href
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body>
<h1>This is a heading</h1>
mystyle.css
body {
background-color: lightblue;
}
h1 {
color: navy;
margin-left: 20px;
}
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
<style>
h1 {
color: orange;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>My mother has <span style="color:blue;font-weight:bold">blue</span> eyes and my father has <span
style="color:darkolivegreen;font-weight:bold">dark green</span> eyes.</p>
<p>The style of this document is a combination of an external style sheet, internal style and inline style sheet</p>
declaration
Selectors
• Elements may be matched depending on how they are nested in the document tree (HTML).
Examples:
h1 {color: green; }
Selectors
• Properties and values tell an HTML element how to • CSS code can be written in a linear
display. format or in a block format.
Grouping Selectors
• Group the same selector with different declarations together on one line.
h1 {color: black;} h1 {
background: white;
Grouping Selectors
h1 {color: yellow;}
h2 {color: yellow;}
h3 {color: yellow;}
OR
Grouping Selectors
This will match <h1> tags, elements with class link, and element with id top-link
– Any styling information that needs to be applied to multiple objects on a page should be done
with a class.
Selectors
Selectors
Selectors: Example #1
<head>
<style>
p{
text-align: center;
color: red;
}
</style>
</head>
<body>
Selectors: Example #2
<head>
<style>
#para1 {
text-align: center;
color: red;
}
</style>
</head>
<body>
Selectors: Example #3
<head>
<style>
.center {
text-align: center;
color: red;
}
</style>
</head>
<body>
Selectors: Example #4
<head>
<style>
p.center {
text-align: center;
color: red;
}
</style>
</head>
<body>
Selectors: Example #5
<head>
<style>
[title~=flower]
{
border:5px solid yellow;
}
</style>
</head>
<body>
<p>The image with the title attribute containing the word "flower" gets a yellow border.</p>
<p><b>Note:</b> For [<i>attribute</i>~=<i>value</i>] to work in IE8 and earlier, a DOCTYPE must be declared.</p>
Selectors: Example #6
<head>
<style>
input[type=text]:enabled {
background: #ffff00;
}
input[type=text]:disabled {
background: #dddddd;
}
</style>
</head>
<body>
<form action="">
First name: <input type="text" value="Mickey"><br>
Last name: <input type="text" value="Mouse"><br>
Country: <input type="text" disabled="disabled" value="Disneyland">
</form>
Selectors: Example #7
<head>
<style>
a:hover
{
background-color:yellow;
}
</style>
</head>
<body>
<a href="http://www.w3schools.com">w3schools.com</a>
<a href="http://www.wikipedia.org">wikipedia.org</a>
Selectors: Example #8
<head>
<style>
input:focus
{
background-color:yellow;
}
</style>
</head>
<body>
<form>
First name: <input type="text" name="firstname" /><br>
Last name: <input type="text" name="lastname" />
</form>
Comments in CSS
Example:
/* This is
a multi-line
comment */
34 Cascading Style Sheets | © SmartCliff | Internal | Version 1.1
Cascading Style Sheets
– Used when there is no CSS information or any other style information in the document
• E.g. margins, paddings and font sizes differ most often and usually developers reset them
* { margin: 0; padding: 0; }
CSS Background
• CSS background properties are used to define the background effects of an element.
• background-color
• background-image
– background-repeat
• background-attachment
• background-position
<head>
<style>
body {
background-color: #b0c4de;
}
</style>
</head>
<head>
<style>
h1 { background-color: #6495ed; }
p { background-color: #e0ffff; }
• By default, a background-image is placed at the top-left corner of an element, and repeated both
vertically and horizontally.
<style> <style>
body { body {
background-image: url("gradient_bg.jpg"); background-image: url("gradient_bg.jpg");
background-repeat: no-repeat; background-repeat: repeat-x;
} }
</style> </style>
<style> <style>
body { body {
background-image: url("gradient_bg.jpg"); background-image: url("gradient_bg.jpg");
background-repeat: repeat-y; /* Default both x and y*/
} }
</style> </style>
<style>
body {
background-image: url("img_tree.jpg");
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<p>Background image example.</p>
<p>The background image is only showing once, but it is disturbing the reader!</p>
<style>
body {
background: #ffffffurl ("img_tree.jpg") no-repeat right top;
margin-right: 200px;
}
</style>
</head>
<body>
<h1>Hello World!</h1>
<p>W3Schools background no-repeat, set position example</p>
<p>Now the background image is only shown once, and it is also positioned away from the text.</p>
<p>In this example we have also added a margin on the right side, so that the background image will not disturb the text.</p>
<body>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
<p>The background-image is fixed. Try to scroll down the page.</p>
• By default, a background-image is placed at the top-left corner of an element, and repeated both
vertically and horizontally.
Value Description
left top, left center, left bottom If you only specify one keyword, the other value will be "center"
right top, right center, right bottom
center top, center center, center bottom
x% y% The first value is the horizontal position and the second value is
the vertical. The top left corner is 0% 0%. The right bottom
corner is 100% 100%. If you only specify one value, the other
value will be 50%. . Default value is: 0% 0%
xpos ypos The first value is the horizontal position and the second value is
the vertical. The top left corner is 0 0.
<head>
<style>
body {
background-image: url('smiley.png');
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center top;
}
</style>
• Every HTML element has a default display value depending on what type of element it is. The default
• A block-level element always starts on a new line and takes up the full width available
• An inline element does not start on a new line and only takes up as much width as necessary.
• Changing an inline element to a block element, or vice versa, can be useful for making the page look
a specific way.
<style> <style>
li { li {
display: block; display: inline;
} }
</style> </style>
</head> </head>
<body> <body>
<p>Display a list of links as a block display property :</p> <p>Display a list of links as a inline display property :</p>
<ul>
<li><a href="/html/default.asp" target="_blank">HTML</a></li>
<li><a href="/css/default.asp" target="_blank">CSS</a></li>
<li><a href="/js/default.asp" target="_blank">JavaScript</a></li>
</ul>
• none - The element does not float (will be displayed just where it occurs in the text). This is default
<style> <style>
.thumbnail { .thumbnail {
float: none; float: left;
width: 110px; width: 110px;
height: 90px; height: 90px;
margin: 5px; margin: 5px;
} }
</style> </style>
</head> </head>
<body>
<h3>Image Gallery</h3>
<p>In this example, the image and the text in the paragraph without float property.</p>
<p><img class="thumbnail" src="rose-flower.jpg" width="107" height="90">
The rose is a type of flowering shrub. Its name comes from the Latin word Rosa. The flowers of the rose grow in many
different colors, from the well-known red rose or yellow rose and sometimes white or purple rose. Roses belong to the family
of plants called Rosaceae.</p>
</body>
• The clear property specifies what elements can float beside the cleared element and on which side.
• The most common way to use the clear property is after you have used a float property on an element.
• When clearing floats, you should match the clear to the float: If an element is floated to the left, then you
• Your floated element will continue to float, but the cleared element will appear below it on the web page.
<head> .div4 {
<style> border: 1px solid red;
.div1 { clear: left;
float: left; }
width: 100px; </style>
height: 50px; </head>
margin: 10px; <body>
border: 3px solid #73AD21; <h2>Without clear</h2>
} <div class="div1">div1</div>
.div2 { <div class="div2">div2 - Notice that div2 is after div1 in the HTML code.
border: 1px solid red; However, since div1 floats to the left, the text in div2 flows around
} div1.</div>
.div3 { <br><br><br>
float: left; <h2>With clear</h2>
width: 100px; <div class="div3">div3</div>
height: 50px; <div class="div4">div4 - Here, clear: left; moves div4 down below the
margin: 10px; floating div3. The value "left" clears elements floated to the left. You can also
border: 3px solid #73AD21; clear "right" and "both".</div>
}
• The overflow property specifies whether to clip the content or to add scrollbars when the content of an
• visible - Default. The overflow is not clipped. The content renders outside the element's box
• hidden - The overflow is clipped, and the rest of the content will be invisible
• scroll - The overflow is clipped, and a scrollbar is added to see the rest of the content
<head> <body>
<style> <p>In this example, the image is taller than the element containing it, and it is floated,
div { so it overflows outside of its container:</p>
border: 3px solid #8AC007;
} <div><img class="img1" src="rose-flower.jpg" alt="Rose" width="100" height="140">
The rose is a type of flowering shrub. Its name comes from the Latin word Rosa. The
.img1 { flowers of the rose grow in many different colors, from the well-known red rose or
float: right; yellow rose and sometimes white or purple rose. Roses belong to the family of plants
} called Rosaceae.</div>
<p style="clear:right">Add a clearfix class with overflow: auto; to the containing
.clearfix { element, to fix this problem:</p>
overflow: auto;
} <div class="clearfix"><img class="img2" src="rose-flower.jpg" alt=“Rose" width="100"
height="140">
.img2 { The rose is a type of flowering shrub. Its name comes from the Latin word Rosa. The
float: right; flowers of the rose grow in many different colors, from the well-known red rose or
} yellow rose and sometimes white or purple rose. Roses belong to the family of plants
</style> called Rosaceae.</div>
</head>
</body>
<head> <body>
<style>
div.scroll { <p>The overflow property specifies what to do if the content of an element exceeds
background-color: #00FFFF; the size of the element's box.</p>
width: 100px;
height: 100px; <p>Result with overflow:scroll</p>
overflow: scroll; <div class="scroll">You can use the overflow property when you want to have better
} control of the layout. The default value is visible.</div>
<head> <body>
<style>
div { <p>The overflow property decides what to do if the content inside an element
background-color: #00FFFF; exceeds the given width and height properties.</p>
width: 150px; <div>You can use the overflow property when you want to have better control of the
height: 350px; layout. Try to change the overflow property to: visible, hidden, scroll, or inherit and
overflow: auto; see what happens. The default value is visible.</div>
}
</style> </body>
</head>
• The position property specifies the type of positioning method used for an element (static, relative, fixed
or absolute).
– Static positioned elements are not affected by the top, bottom, left, and right properties.
– Setting the top, right, bottom, and left properties of a relatively-positioned element will cause it to be
adjusted away from its normal position.
• An element with position: fixed; is positioned relative to the viewport, which means it always stays in the
• An element with position: absolute; is positioned relative to the nearest positioned ancestor (instead of
– However; if an absolute positioned element has no positioned ancestors, it uses the document body,
• The z-index property specifies the stack order of an element (which element should be placed in front
• An element with greater stack order is always in front of an element with a lower stack order.
</body>
• All HTML elements can be considered as boxes. In CSS, the term "box model" is used when talking
about design and layout.
• The CSS box model is essentially a box that wraps around every HTML element. It consists of: margins,
borders, padding, and the actual content.
• The CSS box-sizing property allows us to include the padding and border in an element's total width and
height.
• content-box: The width and height properties (and min/max properties) includes only the content. Border
and padding are not included
• border-box: The width and height properties (and min/max properties) includes content, padding and
border
• Flexbox makes it easier to design flexible and responsive layout structures without using float or
positioning.
• It helps to align items, distribute space dynamically, and order elements as needed.
Basic Terminology:
• Flex Container: The parent element where the display: flex; property is applied.
<head>
<style>
.flex-container {
display: flex;
}
.flex-item {
padding: 10px;
border: 1px solid #ccc;
}
</style>
</head>
<body>
<div class="flex-container">
<div class="flex-item">Item 1</div>
<div class="flex-item">Item 2</div>
<div class="flex-item">Item 3</div>
</div>
</body>
• align-content: Aligns flex lines when there is extra space in the cross axis.
It controls whether the flex container is single-line or multi-line, and the direction of the cross-axis.
• wrap: Flex items will wrap onto multiple lines, from top to bottom.
• wrap-reverse: Flex items will wrap onto multiple lines, from bottom to top.
• space-between: Items are evenly distributed; the first item on the start line, last item on the end line.
• space-around: Items are evenly distributed with equal space around them.
• space-evenly: Items are distributed so that the space between any two items (and the space to the
edges) is equal.
It aligns flex lines when there is extra space in the cross-axis. It applies only when there are multiple flex
• space-between: Lines are evenly distributed; the first line is at the start, the last line at the end.
• space-around: Lines are evenly distributed with equal space around them.
• flex-basis: Defines the default size of an element before the remaining space is distributed.
• align-self: Allows the default alignment (or the one specified by align-items) to be overridden for
• Conciseness: It simplifies your code by combining three properties into one, making your stylesheets
• Order Independence: You can specify the values in any order, and the browser will interpret them
correctly.
• If we set only the flex-grow and flex-shrink values, flex basis would default to zero. This is called
an absolute flex, when we set only the flex-basis, you get a relative flex .
• Absolute flex: flex: 1 1; //flex-basis defaults to 0;
• Relative flex: flex-basis: 200px; //only flex-basis is set
• Flex items will never shrink below their minimum content size, which is determined by the length of the
longest word or fixed-size elements within them. If you need to force shrinking beyond this point, you
• flex: auto (equivalent to flex: 1 1 auto): This is the most common case. Items become fully flexible,
having a default width based on their content. They will grow proportionally to fill the available space
and shrink if necessary to fit the container.
• flex: none (equivalent to flex: 0 0 auto): This cancels the flexibility of the item. It neither grows nor
shrinks to fill the space in the container, maintaining its original size (based on content or defined
width/height). This is often used for elements with fixed dimensions.
• flex: initial (equivalent to flex: 0 1 auto): Resets values to the default, where items will shrink if
there's not enough space but won't expand beyond their content size.
• flex: <positive-number> (Caution!): Using a single positive number can be misleading. For example,
flex: 1 actually translates to flex: 1 1 0. This sets flex-grow to 1 (grow proportionally), but also sets flex-
basis to 0, essentially overriding the item's default size and potentially causing unexpected layout
behavior.
84 Cascading Style Sheets | © SmartCliff | Internal | Version 1.1
Cascading Style Sheets
It allows the default alignment (or the one specified by align-items) to be overridden for individual flex
items.
• auto: Default. The element inherits its parent's align-items property, or stretch if not set.
• baseline: Aligns the item such that its baseline aligns with the baseline of the parent.
CSS Grid
• Grid is a layout system that uses a grid with rows and columns.
• Grid items are then added to fill the grid container. Grid items are the immediate child elements of the
container.
• Grid lines are the horizontal and vertical dividing lines between the rows and columns.
CSS Grid
• Grid cells are the individual units of a grid, much like table cells.
• Grid tracks are the zones between two adjacent grid lines.
PROPERTY DESCRIPTION
grid A shorthand property for a grid container. Sets all grid properties in a single
declaration.
grid-area A shorthand property for a grid item. Sets the item's size and location in a grid.
grid-auto-columns A grid container property that sets the size of a grid column.
grid-auto-flow A grid container property that sets how auto-placed items flow in the grid.
grid-auto-rows A grid container property that sets the size of a grid row.
grid-column A shorthand property for a grid item that sets the element's size and location within
a column.
grid-column-end An item property that sets the element's end position within the grid column.
grid-column-gap A grid container property that sets the gap (gutter) between the columns.
grid-column-start An item property that sets the element's start position within the grid column.
PROPERTY DESCRIPTION
grid-gap A grid container property that sets the gap (gutter) between the rows and columns.
grid-row An item property that sets the size and location within the row.
grid-row-end An item property that sets the element's end position within the grid row.
grid-row-gap A grid container property that sets the gap (gutter) between the rows.
grid-row-start An item property that sets the element's start position within the grid row.
grid-template A grid container property that is a shorthand for defining rows, columns, and areas.
grid-template- Defines the container line names and track sizing functions of the columns.
columns
grid-template-rows Defines the container line names and track sizing functions of the rows.
CSS Grid
CSS Icons
• Font Awesome: Extensive collection, free and paid plans [Font Awesome fontawesome.com]
• Material Design Icons: Google's design language, clean and consistent [Material Design Icons
material.io]
• Bootstrap Icons: Integrates seamlessly with Bootstrap framework [Bootstrap Icons getbootstrap.com]
CSS Grid
CSS3 Evolution
• Cascading Style Sheets, level 1 (CSS1) was came out of W3C as a recommendation in December
1996.
• This version describes the CSS language as well as a simple visual formatting model for all the HTML
tags.
e.g. printers and aural devices, downloadable fonts, element positioning, and tables.
CSS3 Evolution
• CSS3 became a W3C recommendation in June 1999 and builds on older versions CSS.
• It has divided into documentation is called as Modules and here each module having new extension
features defined in CSS2.
– Media Queries
– Namespaces
– Selectors Level 3
– Color
• There’s a huge amount of improvements over the last version, like the ability to easily add video and
Backwards compatible
• That old site running on a previous CSS version can be reworked with CSS3.
• CSS3 is broken up into many individual modules, improving both functionality and ease of working that
it makes CSS3 a lot easier to handle.
• The most important modules include Selectors, Color, Box Model, Backgrounds and Borders, Text
Effects, 2D/3D Transformations and user interface.
• Though many of these are in old CSS specifications, they have been split into small functional pieces
called modules in CSS3.
• With the modular structure and new functionalities, CSS3 makes it much easier to make changes.
• The speed of website built with CSS to the same one with CSS3 was compared by ‘The Smashing
Magazine’.
• According to the results, CSS3 really pays off for production time and size.
• Multiple background: Multiple background images can be included on a page and layered.
• CSS3 background size: The CSS3 background-size property allows to specify the size of these
background images
• Borders and text effects: CSS3 has also managed to set new benchmarks in development speed
CSS3
• Each browser still implementing slightly different syntax for certain properties:
Opera (in most cases) uses the default with no prefix but in some cases you will see
– o – <property>;
CSS3
.div2
{
• CSS3 Rounded corners are used to add special width:300px;
height:300px;
colored corner to body or text by using the border-
border: 3px solid #000;
• Makes creating rounded divs a breeze //Prefix to make this work in Firefox
-moz-border-radius:30px;
//Prefix to make this work in webkit
-webkit-border-radius:30px;
browsers
}
• border-radius: Use this element for setting four boarder radius property
• border-top-left-radius: Use this element for setting the boarder of top left corner
• border-top-right-radius: Use this element for setting the boarder of top right corner
• border-bottom-right-radius: Use this element for setting the boarder of bottom right corner
• border-bottom-left-radius: Use this element for setting the boarder of bottom left corner
<html>
<head>
<style>
border-radius: 25px;
background: #8AC007;
padding: 20px;
width: 200px;
height: 150px;
</style>
</head>
<body>
</body>
</html>
<html>
<head>
<style>
padding: 20px;
width: 200px;
height: 150px;
</style>
</head>
Rounded Corners!
<body>
</body>
</html>
• CSS Border image property is used to add image boarder to some elements.
• you don't need to use any HTML code to call boarder image.
– border-image-repeat: Used to set the boarder image as rounded, repeated and stretched
• Markup:
CSS3 Shadows
– Text shadow
– Box Shadow
CSS3 Shadows
CSS3 Backgrounds
• CSS Multi background property is used to add one or more images at a time without HTML code, We can
add images as per our requirement.
• Sample Markup:
background-size:cover;
background-size:contain;
• CSS Multi background property is used to add one or more images at a time without HTML code, We can
– Background: Used to setting all the background image properties in one section
• Multi background property is accepted to add different sizes for different images.
#multibackground {
• Each image is having specific sizes as 50px, 130px and auto size.
CSS3-Colors
– RGBA colors
– HSL colors
– HSLA colors
– Opacity
CSS3-Colors
• It is an extension of CSS2,Alpha specifies the opacity of a color and parameter number is a numerical
CSS3-Colors
• Here Hue is a degree on the color wheel, saturation and lightness are percentage values between 0 to
100%.
CSS3-Colors
• Alpha value specifies the opacity of the color as a number between 0.0 to 1.0.
CSS3-Colors
#g1 {background-color:rgb(255,0,0);opacity:0.6;}
#g2 {background-color:rgb(0,255,0);opacity:0.6;}
#g3 {background-color:rgb(0,0,255);opacity:0.6;}
CSS3-Colors
<html>
<head>
<style>
#p1 {background-color:rgba(255,0,0,0.3);}
#g2 {background-color:hsl(120,100%,75%);}
#d3 {background-color:hsla(120,100%,25%,0.3);}
#m1 {background-color:rgb(255,0,0);opacity:0.6;}
</style>
</head>
<body>
<p>RGBA colors:</p>
<p id = "p1">Red</p>
<p id = "g2">Normal Green</p>
<p id = "d3">Green</p>
<p id = "m1">Red</p>
</body></html>
CSS3 - Gradients
• Types of gradients
– Linear Gradients(down/up/left/right/diagonally)
– Radial Gradients
• Text Overflow
• Word Break
• Text Shadow
• Various values
– text-overflow: used to determines how overflowed content that is not displayed is signaled to users
– word-wrap: Used to break the line and wrap onto next line
• The text-overflow property determines how overflowed content that is not displayed is signalled to users.
<b>Original Text:</b>
<p> The text-overflow property determines how overflowed
content that is not displayed is signaled to users. </p>
<b>Text overflow:clip:</b>
<p class = "text1"> The text-overflow property determines
how overflowed content that is not displayed is signaled to
users. </p>
<b>Text overflow:ellipsis</b>
<p class = "text2"> The text-overflow property determines
how overflowed content that is not displayed is signaled to
users. </p>
138 Cascading Style Sheets | © SmartCliff | Internal | Version 1.1 </body> </html>
<html>
CSS3 Features
<head>
CSS Text Properties – Word Breaking <style>
p.text1 {
width: 140px; border: 1px solid #000000;
word-break: keep-all; }
p.text2 {
width: 140px; border: 1px solid #000000;
word-break: break-all; }
</style>
</head>
<body>
<b>line break at hyphens:</b>
<p class = "text1">
The text-overflow property determines how overflowed
content that is not displayed is signaled to users. </p>
<b>line break at any character</b>
<p class = "text2">
The text-overflow property determines how overflowed
content that is not displayed is signaled to users. </p>
</body>
</html>
139 Cascading Style Sheets | © SmartCliff | Internal | Version 1.1
CSS3 Features
• Word wrapping is used to break the line and wrap onto next line
• Format: word-wrap:break-word|normal;
p{
word-wrap: break-word;
• No IE support
CSS3 Transformations
• 2D transforms are used to re-change the element structure as translate, rotate, scale, and skew.
• 2D transforms:
– Translate
– Rotate
– Scale
– Skew
CSS3 3D Transformations
• Using with 3D transforms, we can move element to x-axis, y-axis and z-axis, Below example clearly
• 3D transforms:
– Translate
– Rotate
– Scale
– Skew
CSS3 Transitions
• Effects that let an element change from one style to another.
• Limited Support – Currently only supported by Webkit based browsers (Chrome, Safari)
• Cautions:
Format:
CSS3 Animations
• Animation is process of making shape changes and creating motions with elements.
• Limited Support – Currently only supported by Webkit based browsers (Chrome, Safari)
@keyframes animation {
to {background-color: green;}
animation-duration: 5s;
• CSS3 supported multi columns to arrange the text as news paper structure.
• Again, No IE support
• Values
– column-count: Used to count the number of columns that element should be divided.
• Things to remember: {
• TrueType Fonts (TTF): TrueType is an outline font standard developed by Apple and Microsoft in the late
1980s, It became most common fonts for both windows and MAC operating systems.
• OpenType Fonts (OTF): OpenType is a format for scalable computer fonts and developed by Microsoft
• The Web Open Font Format (WOFF): WOFF is used for develop web page and developed in the year of
2009. Now it is using by W3C recommendation.
• SVG Fonts/Shapes: SVG allow SVG fonts within SVG documentation. We can also apply CSS to SVG
with font face property.
• Embedded OpenType Fonts (EOT): EOT is used to develop the web pages and it has embedded in
webpages so no need to allow 3rd party fonts
• Responsive web design makes the web page look good on all
devices.
Screen resolutions
The Viewport
• The viewport varies with the device, and will be smaller on a mobile phone than on a computer screen.
• Before tablets and mobile phones, web pages were designed only for computer screens, and it was
common for web pages to have a static design and a fixed size.
• Then, when we started surfing the internet using tablets and mobile phones, fixed size web pages
• Users are used to scroll websites vertically on both desktop and mobile devices - but not horizontally!
• So, if the user is forced to scroll horizontally, or zoom out, to see the whole web page it results in a
• HTML5 introduced a method to let web designers take control over the viewport, through
• The <meta> tag does not display on the webpage, but it is used by browsers which scan the site or
• This gives the browser instructions on how to control the page's dimensions and scaling.
• The width=device-width part sets the width of the page to follow the screen-width of the device
• The initial-scale=1.0 part sets the initial zoom level when the page is first loaded by the browser.
161 Cascading Style Sheets | © SmartCliff | Internal | Version 1.1
CSS3 Features
The Viewport
• CSS media queries is used to assign different stylesheets depending on browser window size.
– resolution
• Using media queries are a popular technique for delivering a tailored style sheet to desktops, laptops,
• A media query consists of a media type and can contain one or more expressions, which resolve to either true
or false.
@media not|only mediatype and (expressions) {
CSS-Code;
}
• A media type, which tells the browser what kind of media this code is for (e.g. print, or screen).
• A media expression, which is a rule, or test that must be passed for the contained CSS to be applied.
• A set of CSS rules that will be applied if the test passes and the media type is correct.
• Unless we use the not or only operators, the media type is optional and the all type will be implied.
164 Cascading Style Sheets | © SmartCliff | Internal | Version 1.1
CSS3 Features
The CSS media query syntax for calling an external stylesheet is like this:
Value Description
speech Used for screenreaders that "reads" the page out loud
Value Description
width The viewport width
height The viewport height
max-width The maximum width of the display area, such as a browser window
min-width The minimum width of the display area, such as a browser window
max-height The maximum height of the display area, such as a browser window
min-height The minimum height of the display area, such as a browser window
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<style>
body {
background-color: pink;
} If the viewport is less than 480 pixels, the
@media screen and (min-width: 480px) {
body { background-color will be pink
background-color: lightgreen;
}
}
</style>
</head>
<body>
<p>Resize the browser window to see the effect!</p>
</body>
</html>
170 Cascading Style Sheets | © SmartCliff | Internal | Version 1.1
CSS3 Features
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<style>
body {
background-color: lightgreen;
} If the viewport is more than 600 pixels, the
@media only screen and (max-width: 600px) {
background-color will be lightgreen
body {
background-color: lightblue;
}}
</style>
</head>
<body>
<p>Resize the browser window. </p>
</body>
</html>
171 Cascading Style Sheets | © SmartCliff | Internal | Version 1.1
CSS3 Features
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
@media screen and (max-width: 900px) and (min-width: 600px) {
div.example {
font-size: 50px;
padding: 50px;
border: 8px solid black;
background: yellow;
}}
</style></head>
<body>
<h2>Change the appearance of DIV on different screen sizes</h2>
<div class="example"> DIV</div>
</body></html>
172 Cascading Style Sheets | © SmartCliff | Internal | Version 1.1
CSS3 Features
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
@media screen and (max-width: 600px) and (min-width: 400px), (min-
width: 650px) {
div.example{
font-size: 50px;
padding: 50px;
border: 8px solid black;
background: yellow;
}}
</style></head>
<body>
<h2>Change the appearance of DIV on different screen sizes</h2>
<div class="example">DIV.</div>
</body></html>
173 Cascading Style Sheets | © SmartCliff | Internal | Version 1.1
CSS3 Features
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body { Landscape
background-color: lightgreen;
}
@media only screen and (orientation: landscape) {
body {
background-color: lightblue;
}
}
</style></head> Portrait
<body>
<p>Resize the browser window. </p>
</body></html>
174 Cascading Style Sheets | © SmartCliff | Internal | Version 1.1
CSS3 Features
Quiz
a) alpha b) aqua
c) Apple d) about
Ans: a) alpha
Quiz
Quiz
Quiz
b) shadow-right:10px
a) box-shadow: 10px 10px
shadow-bottom:10px;
5px grey;
shadow-color: grey;
d) alpha-effect[shadow]:
c) shadow-color: grey;
10px 10px 5px grey
Quiz
Quiz
a) object-rotation: b)transform:rotate(30d
30deg; eg);
Ans: b) transform:
rotate(30deg);
Quiz
Quiz
a) id b) class
c) text d) bit
Ans: a) id
Quiz
a) opacity b) filter
c) visibility d) overlay
Ans: c) opacity
Quiz
a) border-collapse b) border-radius
Ans: b) border-radius