CSS Book Technosters
CSS Book Technosters
Table of Contents
What is CSS ..................................................................................................................................................... 4
Advantages of CSS .......................................................................................................................................... 4
CSS Syntax ....................................................................................................................................................... 4
How to add CSS ............................................................................................................................................... 5
Inline CSS..................................................................................................................................................... 5
Disadvantages of Inline CSS .................................................................................................................... 5
Internal CSS ................................................................................................................................................. 5
Disadvantages of Internal CSS ................................................................................................................ 5
External CSS ................................................................................................................................................ 5
External CSS is used to apply CSS on multiple pages or all pages. Here, we write
all the CSS code in a css file. Its extension must be .css for example style.css........ 5
Import another CSS file in our CSS file. ....................................................................................................... 6
CSS Comments ................................................................................................................................................ 6
CSS Selectors ................................................................................................................................................... 7
Universal ..................................................................................................................................................... 7
type ............................................................................................................................................................. 7
compound/ group ....................................................................................................................................... 7
class............................................................................................................................................................. 8
id ................................................................................................................................................................. 8
attribute ...................................................................................................................................................... 8
descendant ............................................................................................................................................... 10
child........................................................................................................................................................... 11
Adjacent sibling (पास मैं / सटा हुआ) ..................................................................................................... 11
general sibling ........................................................................................................................................... 12
first child ................................................................................................................................................... 12
last child .................................................................................................................................................... 13
nth child .................................................................................................................................................... 13
first line ..................................................................................................................................................... 15
first letter .................................................................................................................................................. 16
:hover ........................................................................................................................................................ 16
active......................................................................................................................................................... 17
Focus ......................................................................................................................................................... 17
CSS Border .................................................................................................................................................... 18
border bottom .......................................................................................................................................... 18
border bottom color ................................................................................................................................. 18
border collapse ......................................................................................................................................... 19
margin ........................................................................................................................................................... 20
margin bottom .......................................................................................................................................... 20
margin left ................................................................................................................................................. 21
margin right............................................................................................................................................... 21
margin top ................................................................................................................................................. 21
padding ......................................................................................................................................................... 21
padding top ............................................................................................................................................... 21
padding right ............................................................................................................................................. 21
padding bottom ........................................................................................................................................ 21
padding left ............................................................................................................................................... 22
width ............................................................................................................................................................. 22
height ............................................................................................................................................................ 22
min height ................................................................................................................................................. 23
max height ................................................................................................................................................ 23
CSS float ........................................................................................................................................................ 24
Position ......................................................................................................................................................... 26
Static Position ........................................................................................................................................... 26
Relative Position ....................................................................................................................................... 26
Absolute Positioning ................................................................................................................................. 27
Fixed Positioning ....................................................................................................................................... 27
top ............................................................................................................................................................. 27
bottom ...................................................................................................................................................... 28
left ............................................................................................................................................................. 28
right ........................................................................................................................................................... 28
Overlapping Elements ................................................................................................................................... 28
z-index ........................................................................................................................................................... 28
Horizontal Navigation Bar ............................................................................................................................. 28
list-style ................................................................................................................................................. 29
line-height ............................................................................................................................................. 29
text-decoration ..................................................................................................................................... 29
CSS Multiple Backgrounds ........................................................................................................................ 29
CSS Background Size ................................................................................................................................. 29
Define Sizes of Multiple Background Images ............................................................................................ 30
Full Size Background Image....................................................................................................................... 30
CSS background-origin Property ............................................................................................................... 31
CSS background-clip Property ................................................................................................................... 32
CSS Gradients ................................................................................................................................................ 32
CSS Linear Gradients .............................................................................................................................. 32
Syntax.................................................................................................................................................. 32
Using Angles ........................................................................................................................................... 33
Syntax.................................................................................................................................................. 33
Using Multiple Color Stops ................................................................................................................... 34
Using Transparency ................................................................................................................................ 34
Repeating a linear-gradient .................................................................................................................. 34
CSS Radial Gradients .............................................................................................................................. 35
Syntax.................................................................................................................................................. 35
CSS Transforms ............................................................................................................................................. 36
CSS 2D Transforms .................................................................................................................................... 36
The translate() Function ........................................................................................................................... 36
The rotate() Method ................................................................................................................................. 36
The scale() Method ................................................................................................................................... 37
The skewX() Method ................................................................................................................................. 38
The skewY() Method ................................................................................................................................. 38
The skew() Method ................................................................................................................................... 38
CSS 3D Transforms ................................................................................................................................. 39
The rotateX() Method ............................................................................................................................ 39
The rotateY() Method............................................................................................................................. 39
The rotateZ() Method ............................................................................................................................ 39
CSS Animations? ..................................................................................................................................... 40
The @keyframes Rule ............................................................................................................................ 40
Delay an Animation ................................................................................................................................ 41
Set How Many Times an Animation Should Run ............................................................................... 41
Run Animation in Reverse Direction or Alternate Cycles .................................................................. 42
What is CSS
CSS was invented by Håkon Wium Lie on October 10, 1994 and maintained
through a group of people within the W3C called the CSS Working Group.
Advantages of CSS
CSS saves time − you can write CSS once and then reuse same sheet in
multiple HTML pages.
Pages load faster − If you are using CSS, you do not need to write HTML
tag attributes every time. Just write one CSS rule of a tag and apply it to all
the occurrences of that tag. So less code means faster download time.
Global web standards − Now HTML attributes are being deprecated and it
is being recommended to use CSS. So it’s a good idea to start using CSS in
all the HTML pages to make them compatible to future browsers.
CSS Syntax
Each declaration includes a CSS property name and a value, separated by a colon.
A CSS declaration always ends with a semicolon, and declaration blocks are
surrounded by curly braces.
h1 {
text-align: center;
color: red;
}
1. In-line CSS
2. Internal/Page/Embed CSS
3. External CSS
Inline CSS
Inline CSS is used to apply CSS on a single line in HTML tag.
Internal CSS
Internal CSS is used to apply on a document or page. It can affect all the elements
of the page. It is written inside the style tag within head section of html.
<style>
p{color:blue}
</style>
External CSS
External CSS is used to apply CSS on multiple pages or all pages. Here, we write all
the CSS code in a css file. Its extension must be .css for example style.css.
p{color:blue}
You need to link this style.css file to your html pages like this:
CSS Comments
Single Line Comment
p{
color: blue;
// This is a single-line comment;
text-align: center;
}
Multi-line Comment
p{
color: blue;
/* This is a
Multi-line comment;
text-align: center; */
}
CSS Selectors
Universal
The universal selector will target all elements in your HTML document.
<style>
* { color:#F00; }
</style>
<h2>Heading content</h2>
<p>Paragraph <b>content</b>...</p>
type
The type selector is used to target elements by their type.
<style>
h2 { color:#06C; }
</style>
<h2>Some Stuff</h2>
<p>My paragraph...</p>
<h2>More Stuff</h2>
<p>My paragraph...</p>
compound/ group
The compound selector represents a comma separated list of selectors. It acts as a
way to target multiple elements by type, class, id, attribute or pseudo class.
<style>
</style>
<h1>Heading Content</h1>
class
Prefixing the dot symbol to a selector allows us to target by class. The class selector
will target all elements with the same class name.
<style>
</style>
id
Prefixing the hash symbol to a selector allows us to target by id. The id selector will
target an element by its unique id.
<style>
</style>
attribute
The attribute selector will target elements that have the specified attributes and
values.
<style>
</style>
Note: ele[att] - target all elements that have the specified attribute:
<style>
</style>
Note:ele[att="val"] - target all elements that have the specified attribute and value:
<style>
</style>
Note:ele[att~="val"]– target all elements that have the specified attribute and the
attribute value is a space separated list of values, one of which matches the
specified value.
<style>
</style>
Note:ele[att^="val"] - target all elements that have the specified attribute and its
value begins with the specified value.
Note: ele[att$="val"] - target elements that have the specified attribute and its
value ends with the specified value.
<style>
</style>
Note:ele[att*="val"] - target all elements that have the specified attribute and its
value contains the specified substring.
descendant
The descendant selector will target an element's descendants. That includes
direct child elements as well as more deeply nested elements that are
grandchildren and great grandchildren.
<style>
</style>
<div>
<ul>
<li>List Item</li>
<li>List Item</li>
<li>List Item</li>
</ul>
</div>
<ul>
<li>List Item</li>
<li>List Item</li>
<li>List Item</li>
</ul>
child
The child selector will target just the specified direct children of an element and not
target all of its descendants of that type.
<style>
</style>
<div>
</div>
<style>
h3 + p {
text-decoration:underline;
</style>
<h3>Some Stuff</h3>
<p>My paragraph...</p>
<p>My paragraph...</p>
<p>My paragraph...</p>
<h3>More Stuff</h3>
<p>My paragraph...</p>
<p>My paragraph...</p>
<p>My paragraph...</p>
general sibling
The general sibling selector will target all specified elements that come after the
specified sibling element.
<style>
h4 ~ p {
font-style:italic;
color:#09F;
</style>
<h2>Some Stuff</h2>
<h4>More Stuff</h4>
first child
The first-child structural pseudo-class selector will target the first nested element of
the specified type or selector.
<style>
</style>
<article>
</article>
<article>
</article>
Technosters Technologies OPC Pvt. Ltd.
www.technosters.com info@technosters.com +91-9759597195
CSS – Cascading Style Sheet 13
last child
The last-child structural pseudo-class selector will target the last element of the
specified type or selector.
<style>
a:last-child {
background: #c04;
</style>
nth child
The nth-child structural pseudo-class selector will target child elements according to
their position in their specified parent element. Define the numeric value for position
in between the parenthesis.
<style>
li:nth-child(2) {
color:#F00;
</style>
<ul>
</ul>
For even/odd
<style>
li:nth-child(even) {
color: red;
li:nth-child(odd) {
color: blue;
</style>
<ul>
</ul>
This creates the same even/odd logic by styling elements that are divisible by a
specified number. This means you can target all element in positions that are
divisible by 5 or any other number.
<style>
li:nth-child(2n+0) {
color: red;
li:nth-child(2n+1) {
color: blue;
</style>
<ul>
</ul>
first line
The first-line pseudo-element selector will target the first formatted line within
elements.
<style>
p::first-line {
color: red;
ul::first-line {
color: orange;
</style>
<ul>
<li>List item</li>
<li>List item</li>
<li>List item</li>
</ul>
first letter
The first-letter pseudo-element selector will target the first letter of a text.
<style>
p::first-letter {
font-size: 24px;
color: #09C;
</style>
:hover
The hover user action pseudo-class selector will target elements when the user
mouse hovers over them.
<style>
.myList li {
background:#CEE7FF;
padding:12px;
margin:4px;
color:#06F;
.myList li:hover {
background:#B7FFC4;
color:#090;
</style>
<ul class="myList">
</ul>
active
The active user action pseudo-class selector will target elements when the user
clicks to interact with them.
<style>
div{
width:200px;
height: 200px;
background: #ccc;
div:active{
background: #c04;
color: #fff;
</style>
Focus
The focus pseudo class selector will target the element that has focus in the
document as the user interacts with various things.
<style>
input:focus {
background:#C4E1FF;
</style>
<input name="email">
<input name="password">
CSS Border
The CSS border property is shorthand for setting the border-width, border-style and
border-color properties in a single declaration.
<style>
h1 {
</style>
border bottom
The CSS border-bottom property is shorthand for setting the width, style and color
of a bottom border in a single declaration.
<style>
div {
</style>
<div>div content</div>
<style>
h2 {
border-bottom-width: 1px;
border-bottom-style: dotted;
border-bottom-color: #CCC;
</style>
<h2>content ...</h2>
<h2>content ...</h2>
border collapse
The CSS border-collapse property is used to separate or collapse borders on HTML
tables or inline table elements.
<style>
#table1 {
border-collapse: collapse;
#table2 {
border-collapse: separated;
</style>
<table id="table1">
<tr>
<td>Cell data</td>
<td>Cell data</td>
</tr>
<tr>
<td>Cell data</td>
<td>Cell data</td>
</tr>
</table>
<hr>
<table id="table2">
<tr>
<td>Cell data</td>
<td>Cell data</td>
</tr>
<tr>
<td>Cell data</td>
<td>Cell data</td></tr></table>
Technosters Technologies OPC Pvt. Ltd.
8/195, Engineer’s Colony, Opp. Omaxe Mall, Bye Pass Road, Agra – 282005.
20 CSS – Cascading Style Sheet
margin
The CSS margin property is CSS shorthand for specifying margin-top, margin-right,
margin-bottom and margin-left properties in a single declaration. One value
provided makes all sides have the same value. Two values provided affects
top/bottom and left /right sides together. Four values sets margin space for each
side separately. The values can be negative.
<style>
div {
width: 550px;
background: #DFEFFF;
padding:10px;
</style>
margin bottom
The CSS margin-bottom property controls margin space on the outside bottom edge
of elements.
<style>
.columns {
margin-bottom: 50px;
background: lightgray;
width: 200px;
height: 200px;
float: left;
</style>
margin left
The CSS margin-left property controls margin space on the outside left edge of
elements.
margin right
The CSS margin-right property controls margin space on the outside right edge of
elements.
margin top
The CSS margin-top property controls margin space on the outside top edge of
elements.
padding
The CSS padding property is CSS shorthand for specifying padding-top, padding-
right, padding-bottom and padding-left properties in a single declaration. We can set
even padding on all four inner sides by using one value instead of four values. Two
values provided affects top/bottom and right/left inner sides together. Four values
sets padding space for each inner side separately. The values can be positive only.
<style>
#div1 {
background:#DFEFFF;
</style>
<div id="div1">
</div>
padding top
The CSS padding-top property is used to create top space inside of elements.
padding right
The CSS padding-right property is used to create right space inside of elements.
padding bottom
The CSS padding-bottom property is used to create bottom space inside of
elements.
padding left
The CSS padding-left property is used to create left space inside of elements.
width
The CSS width property is used to specify the width for block display elements, not
including padding, margin or border space.
<style>
div, h3, a, p{
background: #CCC;
padding: 20px;
p{ width: 80%; }
</style>
<div>div content</div>
<h3>h3 content</h3>
<a>a content</a>
<p>p content</p>
height
The CSS height property is used to specify the height of block elements, not
including padding, margin or border space.
<style>
#container {
width: 500px;
height: 300px;
background: #9FCFFF;
</style>
min height
The CSS min-height property is used to set the minimum height that an element.
Can be use with the max-height property to create height range for an element.
<style>
#div1 {
min-height: 90px;
background: #FFCAFF;
</style>
<div id="div1">
</div>
Note: If content height greater then element’s height with CSS property min-height
so element’s height increase basis on content.
max height
The CSS max-height property is used to set the maximum height that an element
can grow to be. Use with min-height to create a height range for the element. Use in
conjunction with the overflow property to show scrollbars or hide content that might
go beyond the max-height of the element.
<style>
#div1 {
max-height: 200px;
min-height: 90px;
background: #FFCAFF;
overflow: auto;
</style>
<div id="div1">
</div>
CSS float
The CSS float property is used to float elements to either the left or right side.HTML
works without float from top to bottom
<style type="text/css">
#div1 {
float: left;
background: #BFFFFF;
padding: 12px;
width: 120px;
height: 60px;
#div2 {
float: right;
background: #FFD9F8;
padding: 12px;
width: 120px;
height: 60px;
</style>
Position
CSS helps you to position your HTML element. You can put any HTML element at
whatever location you like. You can specify whether you want the element
positioned relative to its natural position in the page or absolute based on its parent
element.
Static Position
HTML elements are positioned static by default. Static positioned elements are not
affected by the top, bottom, left, and right properties.
<html>
<head>
</head>
<body>
<div style="position:static;background-color:yellow;">
</div>
</body>
</html>
Relative Position
Relative positioning changes the position of the HTML element relative to where it
normally appears. So "left:20" adds 20 pixels to the element's LEFT position.
You can use two values top and left along with the position property to move an
HTML element anywhere in the HTML document.
<html>
<head>
</head>
<body>
<div style="position:relative;left:80px;top:20px;background-color:yellow;">
</div>
</body>
</html>
Absolute Positioning
An element with position: absolute is positioned at the specified coordinates relative
to your screen top-left corner.
You can use two values top and left along with the position property to move an
HTML element anywhere in the HTML document.
<html>
<head>
</head>
<body>
</div>
</body>
</html>
Fixed Positioning
Fixed positioning allows you to fix the position of an element to a particular spot on
the page, regardless of scrolling. Specified coordinates will be relative to the browser
window.
You can use two values top and left along with the position property to move an
HTML element anywhere in the HTML document.
<html>
<head>
</head>
<body>
</div>
</body>
</html>
top
The CSS top property is used to offset the top position of relative, absolute and fixed
position elements.
bottom
The CSS bottom property is used to offset the bottom position of relative, absolute
and fixed position elements.
left
The CSS left property is used to offset the left position of relative, absolute and fixed
position elements.
right
The CSS right property is used to offset the right position of relative, absolute and
fixed position elements.
Overlapping Elements
When elements are positioned, they can overlap other elements.
z-index
The z-index property specifies the stack order of an element (which element should
be placed in front of, or behind, the others).
nav ul li a{
float: left;
</style>
<nav><ul>
<li><a href="#">Home</a></li>
<li><a href="#">Home</a></li>
<li><a href="#">Home</a></li>
<li><a href="#">Home</a></li>
<li><a href="#">Home</a></li>
</ul></nav>
list-style
list style : none; is used to remove bullets from unordered list.
line-height
The line-height property specifies the line height for text.
text-decoration
The text-decoration property specifies the decoration added to text.
(none|underline|overline|line-through)
CSS allows you to add multiple background images for an element, through
the background-image property.
The different background images are separated by commas, and the images are
stacked on top of each other, where the first image is closest to the viewer.
#example1 {
background-image: url(img-1.ext), url(img-2.ext);
background-position: right bottom, left top;
background-repeat: no-repeat, repeat;
}
#example2 {
background: url(img-1.ext) right bottom no-repeat, url(img-2.ext) left top
repeat;
}
The CSS background-size property allows you to specify the size of background
images.
The size can be specified in lengths, percentages, or by using one of the two
keywords: contain or cover.
#div1 {
background: url(img.ext);
background-size: 100px 80px;
background-repeat: no-repeat;
}
The two other possible values for background-size are contain and cover.
The contain keyword scales the background image to be as large as possible (but
both its width and its height must fit inside the content area). As such, depending on
the proportions of the background image and the background positioning area, there
may be some areas of the background which are not covered by the background
image.
The cover keyword scales the background image so that the content area is
completely covered by the background image (both its width and height are equal to
or exceed the content area). As such, some parts of the background image may not
be visible in the background positioning area.
#div1 {
background: url(img.ext);
background-size: contain;
background-repeat: no-repeat;
}
#div2 {
background: url(img.ext);
background-size: cover;
background-repeat: no-repeat;
}
The background-size property also accepts multiple values for background size
(using a comma-separated list), when working with multiple backgrounds.
The following example has three background images specified, with different
background-size value for each image:
#example1 {
background: url(img-1.ext) left top no-repeat, url(img-2.ext) right bottom
no-repeat, url(img-3.ext) left top repeat;
background-size: 50px, 130px, auto; /* img-1,img-2, img-3 */
}
Now we want to have a background image on a website that covers the entire
browser window at all times.
Fill the entire page with the image (no white space)
Scale image as needed
Center image on page
Do not cause scrollbars
html {
background: url(img.ext) no-repeat center fixed;
background-size: cover;
}
border-box - the background image starts from the upper left corner of the
border
padding-box - (default) the background image starts from the upper left
corner of the padding edge
content-box - the background image starts from the upper left corner of
the content
#example1 {
border: 10px solid black;
padding: 35px;
background: url(img.ext);
background-repeat: no-repeat;
background-origin: padding-box; /* default */
}
#example2 {
border: 10px solid black;
padding: 35px;
background: url(img.ext);
background-repeat: no-repeat;
background-origin: content-box;
}
#example3 {
border: 10px solid black;
padding: 35px;
background: url(img.ext);
background-repeat: no-repeat;
background-origin: border-box;
}
The CSS background-clip property specifies the painting area of the background.
#example1 {
border: 10px dotted black;
padding: 35px;
background: yellow;
background-clip: border-box; /* default*/
}
#example2 {
border: 10px dotted black;
padding: 35px;
background: yellow;
background-clip: padding-box;
}
#example3 {
border: 10px dotted black;
padding: 35px;
background: yellow;
background-clip: content-box;
}
CSS Gradients
CSS gradients let you display smooth transitions between two or more specified
colors.
Syntax
background: linear-gradient (direction, color-stop1, color-stop2, ...);
The following example shows a linear gradient that starts at the top. It starts red,
transitioning to yellow:
#grad {
background: linear-gradient(blue, yellow);
}
The following example shows a linear gradient that starts from the left. It starts red,
transitioning to yellow:
#grad {
background: linear-gradient(to right,blue , yellow);
}
You can make a gradient diagonally by specifying both the horizontal and vertical
starting positions.
The following example shows a linear gradient that starts at top left (and goes to
bottom right). It starts red, transitioning to yellow:
#grad {
background: linear-gradient(to bottom right, blue, yellow);
}
Using Angles
If you want more control over the direction of the gradient, you can define an angle,
instead of the predefined directions (to bottom, to top, to right, to left, to bottom
right, etc.).
Syntax
background: linear-gradient(angle, color-stop1, color-stop2);
The angle is specified as an angle between a horizontal line and the gradient line.
#grad {
background: linear-gradient(-90deg, red, yellow);
}
#grad {
background: linear-gradient(red, yellow, green);
}
The following example shows how to create a linear gradient (from left to right) with
the color of the rainbow and some text:
#grad {
background: linear-gradient(to right,
red,orange,yellow,green,blue,indigo,violet);
}
Using Transparency
CSS gradients also support transparency, which can be used to create fading effects.
To add transparency, we use the rgba() function to define the color stops. The last
parameter in the rgba() function can be a value from 0 to 1, and it defines the
transparency of the color: 0 indicates full transparency, 1 indicates full color (no
transparency).
The following example shows a linear gradient that starts from the left. It starts fully
transparent, transitioning to full color red:
#grad {
background: linear-gradient(to right, rgba(255,0,0,0), rgba(255,0,0,1));
}
Repeating a linear-gradient
The repeating-linear-gradient() function is used to repeat linear gradients:
#grad {
background: repeating-linear-gradient(red, yellow 10%, green 20%);
}
To create a radial gradient, you must also define at least two-color stops.
Syntax
background: radial-gradient(shape size at position, start-color, ..., last-
color);
The following example shows a radial gradient with evenly spaced color stops:
#grad {
background: radial-gradient(blue, yellow, green);
}
The following example shows a radial gradient with differently spaced color stops:
#grad {
background: radial-gradient(red 5%, yellow 15%, green 60%);
}
CSS Transforms
CSS transforms allow you to translate, rotate, scale, and skew elements.
A transformation is an effect that lets an element change shape, size and position.
CSS 2D Transforms
In this chapter you will learn about the following 2D transformation methods:
translate()
rotate()
scale()
skewX()
skewY()
div {
-ms-transform: translate(50px, 100px); /* IE 9 */
-webkit-transform: translate(50px, 100px); /* Safari */
transform: translate(50px, 100px);
}
div {
-ms-transform: rotate(20deg); /* IE 9 */
-webkit-transform: rotate(20deg); /* Safari */
transform: rotate(20deg);
}
div {
-ms-transform: rotate(-20deg); /* IE 9 */
-webkit-transform: rotate(-20deg); /* Safari */
transform: rotate(-20deg);
}
div {
-ms-transform: rotateY(-20deg); /* IE 9 */
-webkit-transform: rotateY(-20deg); /* Safari */
transform: rotateY(-20deg);
}
div {
-ms-transform: rotateY(20deg); /* IE 9 */
-webkit-transform: rotateY(20deg); /* Safari */
transform: rotateY(20deg);
}
div {
-ms-transform: rotateX(-20deg); /* IE 9 */
-webkit-transform: rotateX(-20deg); /* Safari */
transform: rotateX(-20deg);
}
div {
-ms-transform: rotateX(20deg); /* IE 9 */
-webkit-transform: rotateX(20deg); /* Safari */
transform: rotateX(20deg);
}
div {
-ms-transform: scale(2, 3); /* IE 9 */
-webkit-transform: scale(2, 3); /* Safari */
transform: scale(2, 3);
}
The following example decreases the <div> element to be half of its original
width and height:
div {
-ms-transform: scale(0.5, 0.5); /* IE 9 */
-webkit-transform: scale(0.5, 0.5); /* Safari */
The skewX() method skews an element along the X-axis by the given angle.
div {
-ms-transform: skewX(20deg); /* IE 9 */
-webkit-transform: skewX(20deg); /* Safari */
transform: skewX(20deg);
}
The skewY() method skews an element along the Y-axis by the given angle.
div {
-ms-transform: skewY(20deg); /* IE 9 */
-webkit-transform: skewY(20deg); /* Safari */
transform: skewY(20deg);
}
The skew() method skews an element along the X and Y-axis by the given
angles.
div {
-ms-transform: skew(20deg, 10deg); /* IE 9 */
-webkit-transform: skew(20deg, 10deg); /* Safari */
transform: skew(20deg, 10deg);
}
Note: If the second parameter is not specified, it has a zero value. So, the
following example skews the <div> element 20 degrees along the X-axis:
div {
-ms-transform: skew(20deg); /* IE 9 */
-webkit-transform: skew(20deg); /* Safari */
transform: skew(20deg);
}
CSS 3D Transforms
CSS allows you to format your elements using 3D transformations.
rotateX()
rotateY()
rotateZ()
#myDiv {
-webkit-transform: rotateX(150deg); /* Safari */
transform: rotateX(150deg);
}
#myDiv {
-webkit-transform: rotateY(130deg); /* Safari */
transform: rotateY(130deg);
}
#myDiv {
-webkit-transform: rotateZ(90deg); /* Safari */
transform: rotateZ(90deg);
}
CSS Animations?
The @keyframes Rule
When you specify CSS styles inside the @keyframes rule, the animation will
gradually change from the current style to the new style at certain times.
Delay an Animation
The animation-delay property specifies a delay for the start of an animation.
The following example has a 2 seconds delay before starting the animation:
div {
width: 100px;
height: 100px;
position: relative;
background-color: red;
animation-name: example;
animation-duration: 4s;
animation-delay: 2s;
}
div {
width: 100px;
height: 100px;
position: relative;
background-color: red;
animation-name: example;
animation-duration: 4s;
animation-iteration-count: 3;
}
Technosters Technologies OPC Pvt. Ltd.
8/195, Engineer’s Colony, Opp. Omaxe Mall, Bye Pass Road, Agra – 282005.
42 CSS – Cascading Style Sheet
The following example uses the value "infinite" to make the animation continue
for ever:
div {
width: 100px;
height: 100px;
position: relative;
background-color: red;
animation-name: example;
animation-duration: 4s;
animation-iteration-count: infinite;
}
The following example will run the animation in reverse direction (backwards):
div {
width: 100px;
height: 100px;
position: relative;
background-color: red;
animation-name: example;
animation-duration: 4s;
animation-direction: reverse;
}
The following example uses the value "alternate" to make the animation run
forwards first, then backwards:
div {
width: 100px;
height: 100px;
position: relative;
background-color: red;
animation-name: example;
animation-duration: 4s;
Technosters Technologies OPC Pvt. Ltd.
www.technosters.com info@technosters.com +91-9759597195
CSS – Cascading Style Sheet 43
animation-iteration-count: 2;
animation-direction: alternate;
}
The following example uses the value "alternate-reverse" to make the animation
run backwards first, then forwards:
div {
width: 100px;
height: 100px;
position: relative;
background-color: red;
animation-name: example;
animation-duration: 4s;
animation-iteration-count: 2;
animation-direction: alternate-reverse;
}