Introduction to CSS-2
Introduction to CSS-2
The border-radius property allows you to add rounded corners border-radius: 75px;
to an element background: url(paper.gif);
You can also specify the radius for each corner with border- background-position: left top;
top-left-radius, border-top-right-radius, border-bottom-left- background-repeat: repeat;
radius and border-bottom-right-radius.
padding: 20px;
<!DOCTYPE html>
<html>
width: 200px;
<head> height: 150px;
<style> }
#chandu1 {
p{ text-align:center;
border-radius: 25px;
background: #73AD21;
color:yellow; }
padding: 20px; </style>
width: 200px;
</head>
height: 150px;
<body>
}
height: 150px;
}
Box Shadows
• Horizontal offset of the shadow the number of pixels that the box-shadow will appear to the
left or the right of the box. A positive value moves the box-shadow to the right
• Vertical offset of the shadow the number of pixels the box-shadow will be shifted up or down
from the box. A positive value moves the box-shadow down.
• Blur radius A blur-radius of 0px would result in a shadow with a sharp edge (no blur). The
greater the value, the more the edges of the shadow are blurred. We used a blur radius of 10px.
height: 200px; border: 3px solid navy; padding: 5px 20px; text-align: center; background: linear-gradient(
45deg, white 15%, plum 50%, purple 75% ); }
background: linear-gradient( to bottom, white 15%, lightsteelblue 50%, navy
75% ); </style>
float: left; margin-right: 15px; } </head>
#horizontal <body>
{ width: 200px; <div><h2>Vertical Linear Gradient</h2></div>
height: 200px; <div id = "horizontal"><h2>Horizontal Linear
Gradient</h2></div>
border: 3px solid orange;
<div id = "angle"><h2>Diagonal Linear
padding: 5px 20px; Gradient</h2></div>
text-align: center; </body>
background: linear-gradient( 90deg, white 15%, yellow 50%, orange 75% ); </html>
margin-right: 15px; }
Radial Gradients
Radial gradients are similar to linear gradients, but the color changes gradually from an inner point (the
start) to an outer circle (the end)
background: radial-gradient(shape size at position, start-color, ..., last-color);
<!DOCTYPE html>
<html>
<head>
<style>
#grad1 {
height: 150px;
width: 200px;
animation-delay specifies the number of seconds (1s in this case) or milliseconds after the page
loads before the animation begins.
The default value is 0. If the animation-delay is negative, such as -3s, the animation will begin
three seconds into its cycle.
animation-iteration-count specifies the number of times the animation will run. The default is 1.
You may use the value infinite to repeat the animation continuously.
animation-direction specifies the direction in which the animation will run. The value alternate
used here specifies that the animation will run in alternating, counterclockwise ,then clockwise.
The default value, normal, would run the animation in the same direction for each cycle.
<html>
<head>
<title>Animation</title>
<style type = "text/css">
img
{
position: relative;
animation: movingImage linear 18s 2 1s alternate;
}
@keyframes movingImage
{
0% {opacity: 0; left: 50px; top: 0px;}
25% {opacity: 1; left: 0px; top: 50px;}
50% {opacity: 0; left: 50px; top: 100px;}
75% {opacity: 1; left: 100px; top: 50px;}
100% {opacity: 0; left: 50px; top: 0px;}
}
</style>
</head>
<body>
<img src = "rvr.jpg" width = "138" height = "180"
alt = "RVRJC">
<div></div>
</body>
</html>
Transitions and Transformations
With CSS transitions, you can change an element’s style over a specified duration for example, you can
vary an element’s opacity from opaque to transparent over a duration of one second.
CSS3 transformations allow you to move, rotate, scale and skew elements.
transition: transform 4s, opacity 2s;
The transform property uses transformation functions, such as rotate and scale, to perform the
transformations.
The rotate transformation function receives the number of degrees. Negative values cause the element
to rotate left.
A value of 720deg would cause the element to rotate clockwise twice.
The scale transformation function specifies how to scale the width and height. The value 1 represents
the original width or original height, so values greater than 1 increase the size and values less than 1
decrease the size.
<html>
<head>
<title>Transitions</title>
<style type = "text/css">
img
{
margin: 80px;
transition: transform 10s;
}
img:hover
{
transform: rotate(360deg) scale(2, 2);
}
</style>
</head>
<body>
<img src = "rvr.jpg" width = "76" height = "100“ alt = "rvrjc">
</body>
</html>
Skew
The CSS skew() function is used to skew elements in a two-dimensional space.
The skew() element performs a shear transformation (also known as a shear mapping or a transvection),
which displaces each point of an element by a given angle in each direction.
Skewing an element is kind of like taking the points of an element, and pushing or pulling them in
different directions, based on a given angle.
CSS transformations also allow you to skew block-level elements, slanting them at an angle either
horizontally (skewX) or vertically (skewY)
The skew() function works like this:
skew(ax) or
skew(ax, ay)
<!DOCTYPE html>
<html>
<head>
<title>skew</title>
<style>
.skewx {
transform-origin: top left;
transform: skew(20deg, 0);
}
.skewy {
transform-origin: top left;
transform: skew( 0,20deg);
</style>
</head>
<body>
<img src="chess.png" alt="Sample image">
<img class="skewx" src="chess.png" alt="Sample image">
<img class="skewy" src="chess.png" alt="Sample image">
</body>
Transitioning Between Images
We can also use the transition property to create the visually beautiful effect of melting one image into
another.
The transition property includes three values.
First, we specify that the transition will occur on the opacity of the image.
The second value is the transition-duration.
The third value( ease-in-out) is the transition timing-function
<html>
<head>
<title>Melting Images</title>
<style type = "text/css">
#cover
{
position: relative;
margin: 0 auto;
}
#cover img
{
position: absolute; left: 0;
transition: opacity 4s ease-in-out;
}
#cover img.top:hover
{ opacity:0; }
</style> </head>
<body>
<div id = "cover">
<img class = "bottom" src = "rvr.jpg" alt = “rvrjc">
<img class = "top" src = "camel.jpg" alt = “camel">
</div>
</body> </html>