05.CSS Advanced Properties
05.CSS Advanced Properties
.corner-each {
border-top-left-radius: 15px;
border-top-right-radius: 50px;
border-bottom-right-radius: 30px;
border-bottom-left-radius: 5px;
}
.corner-4 {
background-color: green;
border-radius: 15px 50px 30px 5px;
}
</style>
</head>
<body>
<div class="corner-each">
Hello
</div>
<div class="corner-4">
Hello
</div>
</body>
2. Set only one, two, three values only
<head>
<style>
div {
border: 2px solid green;
width: 200px;
height: 100px;
margin-top: 20px;
padding: 50px;
}
.one {
border-radius: 50px;
}
.two {
border-radius: 50% 30px;
}
.three {
border-radius: 40px 60px 15px;
}
</style>
</head>
<body>
<div class="one">
One value is for all corners
</div>
<div class="two">
If two values:<br/>
First is for top-left and bottom-right<br/>
Second is for top-right and bottom-left
</div>
<div class="three">
If three values:<br/>
First is for top-left<br/>
Second is for top-right and bottom-left<br/>
Third is for bottom-right
</div>
</body>
3. Set border to ellipse
<head>
<style>
#corner1 {
border-radius: 50px / 15px;
background: #73AD21;
padding: 20px;
width: 200px;
height: 150px;
}
#corner2 {
border-radius: 15px / 50px;
background: #73AD21;
padding: 20px;
width: 200px;
height: 150px;
}
#corner3 {
border-radius: 50%;
background: #73AD21;
padding: 20px;
width: 200px;
height: 150px;
}
</style>
</head>
<body>
<p>Elliptical border - border-radius: 50px / 15px:</p>
<p id="corner1"></p>
#border-img-stretch {
border: 10px solid transparent;
padding: 15px;
border-image: url(border.png) 30 stretch;
}
</style>
</head>
<body>
<div>
Original Image is <img src="border.png"/>
</div>
<br/>
<div id="border-img-round">
border-image: url(border.png) 30 round;
</div>
<br/>
<div id="border-img-stretch">
border-image: url(border.png) 30 stretch;
</div>
</body>
2. Border Image using Separate properties
<head>
<style>
div {
border: 10px solid transparent;
padding: 15px;
border-image-source: url(border.png);
}
#bd1 {
border-image-slice: 5 fill;
}
#bd2 {
border-image-slice: 30;
border-image-repeat: space;
border-image-width: 20px;
}
#bd3 {
border-image-slice: 30;
border-image-repeat: space;
border-image-outset: 10px;
}
</style>
</head>
<body>
<div id="bd1">
border-image-slice: 5 fill;
</div>
<br/>
<div id="bd2">
border-image-slice: 30;
border-image-repeat: space;
border-image-width: 20px;
</div>
<br/>
<div id="bd3">
border-image-slice: 30;
border-image-repeat: space;
border-image-outset: 10px;
</div>
</body>
Color Functions
Options of function to set color values in CSS, including RGB, saturation, opacity, and taking current color
(currentcolor)
opacity Sets the opacity / transparency of the Number from 0.0 - 1.0
element
1. Using RGB, RGBA, HSL, and HSLA
<head>
<style>
div {
display: inline-block;
width: 100px;
height: 100px;
text-align: center;
}
.rgb {
background-color: rgb(200, 143, 87);
}
.rgba {
background-color: rgb(154, 80, 210, 0.6);
}
.hsl {
background-color: hsl(120, 60%, 30%);
}
.hsla {
background-color: hsla(240, 37%, 54%, 0.4);
}
</style>
</head>
<body>
<div class="rgb">
Web Programming
</div>
<div class="rgba">
Web Programming
</div>
<br/>
<div class="hsl">
Web Programming
</div>
<div class="hsla">
Web Programming
</div>
</body>
2. Using currentcolor and opacity
<head>
<style>
div {
color: blue;
border: 1px dashed currentcolor;
height: 200px;
width: 200px;
}
.opaque {
color: red;
background-color: blue;
opacity: 0.4;
}
</style>
</head>
<body>
<div>
Web Programming
</div>
<br/>
<div class="opaque">
Background is opaque
</div>
</body>
Tooltips
Add tooltip in the elements to help user when the user hovers the pointer to a certain element
1. Right Tooltip
<head>
<style>
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
.tooltip:hover .tooltiptext {
visibility: visible;
}
</style>
</head>
<body style="text-align:center;">
<p>Move the mouse over the text below:</p>
<div class="tooltip">Hover over me
<span class="tooltiptext">Tooltip text</span>
</div>
</body>
2. Left Tooltip
<head>
<style>
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
.tooltip:hover .tooltiptext {
visibility: visible;
}
</style>
</head>
<body style="text-align:center;">
<p>Move the mouse over the text below:</p>
<div class="tooltip">Hover over me
<span class="tooltiptext">Tooltip text</span>
</div>
</body>
3. Top Tooltip
<style>
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
.tooltip:hover .tooltiptext {
visibility: visible;
}
</style>
<body style="text-align:center;">
</body>
4. Bottom Tooltip
<style>
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
.tooltip:hover .tooltiptext {
visibility: visible;
}
</style>
<body style="text-align:center;">
<p>Move the mouse over the text below:</p>
</body>
Gradient Functions
Function to set color in gradients. There are 3 (three) main gradient types: Linear, Radial, and Conic gradients.
Linear is defined by the directions (up, down, left, right, diagonal), Radial is defined by the center, and Conic is
defined by the rotation of the center point.
#grd {
color: white;
background-image: linear-gradient(63deg, red, blue, green);
}
#right-grd {
color: black;
background-image: linear-gradient(to right, rgba(100, 0, 0, 0.1),
rgba(255, 0, 0, 1.0));
}
#repeat-grd {
background-image: repeating-linear-gradient(135deg, pink, red,
orange);
}
</style>
</head>
<body>
<div id="grd">
Hello World
</div>
<br/>
<div id="right-grd">
Web Programming
</div>
<br/>
<div id="repeat-grd">
Repeating Color Gradient
</div>
</body>
2. Radial Gradient variations
<head>
<style>
div {
height: 200px;
width: 200px;
}
#grd {
color: white;
background-image: radial-gradient(pink, purple, black);
}
#right-grd {
color: black;
background-image: radial-gradient(circle, red, yellow, blue);
}
#repeat-grd {
background-image: repeating-radial-gradient(pink, purple 10%,
violet 15%);
}
</style>
</head>
<body>
<div id="grd">
Hello World
</div>
<br/>
<div id="right-grd">
Web Programming
</div>
<br/>
<div id="repeat-grd">
Repeating Color Gradient
</div>
</body>
3. Conic Gradient variations
<head>
<style>
div {
height: 200px;
width: 200px;
}
#grd {
color: white;
background-image: conic-gradient(pink, purple, black);
}
#right-grd {
color: black;
background-image: conic-gradient(red 120deg, yellow 120deg,
blue);
}
#repeat-grd {
background-image: repeating-conic-gradient(pink, purple 10%,
violet 15%);
}
</style>
</head>
<body>
<div id="grd">
Hello World
</div>
<br/>
<div id="right-grd">
Web Programming
</div>
<br/>
<div id="repeat-grd">
Repeating Color Gradient
</div>
</body>
Shadow Manipulation
Add effects of shadow in the text or element
.pink-shadow {
text-shadow: 3px 3px pink;
}
.red-blur {
text-shadow: 3px 3px 5px red;
}
</style>
</head>
<body>
<h2 class="shadow1">
Text Shadow
</h2>
<h2 class="pink-shadow">
Text Shadow
</h2>
<h2 class="red-blur">
Text Shadow
</h2>
</body>
2. Multi Shadow and Text Border
<head>
<style>
.multi-shadow {
color: white;
text-shadow: 2px 2px 3px black, 0 0 30px red, 0 0 2px yellow;
}
.text-border {
color: yellow;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
</style>
</head>
<body>
<h2 class="multi-shadow">
Text Shadow
</h2>
<h2 class="text-border">
Text Border
</h2>
</body>
3. Box Shadow
<head>
<style>
div {
background-color: orange;
width: 150px;
height: 150px;
}
.single {
box-shadow: 10px 10px;
}
.multi {
box-shadow: 5px 5px blue, 10px 10px red, 15px 15px green;;
}
</style>
</head>
<body>
<div class="single">
Box with shadow
</div>
<br/>
<div class="multi">
Box with Multi Shadow
</div>
</body>
Transformation
Transform object or element using CSS in 2-dimensional and 3-dimensional aspects
transform-origin Change position of transformed elements x-axis (left, center, right, length,
X-axis and Y-axis (2D) %)
X-axis, Y-axis, Z-axis (3D) y-axis (top, center, bottom,
length, %)
z-axis (length)
perspective-origin (3D Only) Defines position from which the x-axis (left, center, right, length,
user is looking at the 3D elements and only %)
the CHILDREN elements will get the effect y-axis (top, center, bottom,
and must be used with perspective property length, %)
div#myDiv1 {
transform: matrix(1, -0.3, 0, 1, 0, 0);
}
div#myDiv2 {
transform: matrix(1, 0, 0.5, 1, 150, 0);
}
</style>
</head>
<body>
<div>
This a normal div element.
</div>
<div id="myDiv1">
Using the matrix() method.
</div>
<div id="myDiv2">
Another use of the matrix() method.
</div>
</body>
3D transformation
1. Rotate by X-Axis
<head>
<style>
div {
width: 300px;
height: 100px;
background-color: yellow;
border: 1px solid black;
}
#rotateX {
transform: rotateX(150deg);
}
</style>
</head>
<body>
<div>
This a normal div element.
</div>
<div id="rotateX">
This div element is rotated 150 degrees.
</div>
</body>
2. Rotate by Y-Axis
<head>
<style>
div {
width: 300px;
height: 100px;
background-color: yellow;
border: 1px solid black;
}
#rotateY {
transform: rotateY(150deg);
}
</style>
</head>
<body>
<div>
This a normal div element.
</div>
<div id="rotateY">
This div element is rotated 150 degrees.
</div>
</body>
3. Rotate by Z-Axis
<head>
<style>
div {
width: 300px;
height: 100px;
background-color: yellow;
border: 1px solid black;
}
#rotateZ {
transform: rotateZ(150deg);
}
</style>
</head>
<body>
<div>
This a normal div element.
</div>
<div id="rotateZ">
This div element is rotated 150 degrees.
</div>
</body>
4. Perspective, using lesser value means closer to the user, and preserve the 3D perspective
<head>
<style>
#div1 {
position: relative;
width: 150px;
height: 150px;
margin-left: 60px;
border: 1px solid blue;
perspective: 100px;
}
#div3 {
position: relative;
width: 150px;
height: 150px;
margin-left: 60px;
border: 1px solid blue;
perspective: none;
}
#div2, #div4 {
position: absolute;
padding: 50px;
border: 1px solid black;
background-color: rgba(100, 100, 100, 0.5);
transform-style: preserve-3d;
transform: rotateX(45deg);
}
</style>
</head>
<body>
<div id="div1">
DIV1
<div id="div2">DIV2</div>
</div>
<br/>
<div id="div3">
DIV3
<div id="div4">DIV4</div>
</div>
</body>
5. Perspective origin
<head>
<style>
#div1 {
position: relative;
height: 150px;
width: 150px;
margin-left: 60px;
border: 1px solid blue;
perspective: 100px;
perspective-origin: left;
}
#div2, #div4, #div6 {
padding: 50px;
position: absolute;
border: 1px solid black;
background-color: red;
background: rgba(100,100,100,0.5);
transform-style: preserve-3d;
transform: rotateX(45deg);
}
#div3 {
position: relative;
height: 150px;
width: 150px;
margin-left: 60px;
border: 1px solid blue;
perspective: 100px;
perspective-origin: bottom right;
}
#div5 {
position: relative;
height: 150px;
width: 150px;
margin-left: 60px;
border: 1px solid blue;
perspective: 100px;
perspective-origin: -90%;
}
</style>
</head>
<body>
<h2>perspective-origin: left:</h2>
<div id="div1">DIV1
<div id="div2">DIV2</div>
</div>
<h2>perspective-origin: bottom right:</h2>
<div id="div3">DIV3
<div id="div4">DIV4</div>
</div>
<h2>perspective-origin: -90%:</h2>
<div id="div5">DIV5
<div id="div6">DIV6</div>
</div>
</body>
6. Create a Cube
<head>
<style>
.ex1 {
perspective: 800px;
}
.cube {
font-size: 4em;
width: 2em;
margin: 1.5em auto;
transform-style: preserve-3d;
transform: rotateX(-45deg) rotateY(30deg);
}
.side {
position: absolute;
width: 2em;
height: 2em;
background: rgba(100,100,100,0.5);
border: 1px solid red;
text-align: center;
line-height: 2em;
}
div:hover {
width: 300px;
}
</style>
</head>
<body>
Hover cursor over the box
<div></div>
</body>
2. Transition using all properties
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: pink;
transition-delay: 0s;
transition-duration: 2s;
transition-property: width;
transition-timing-function: linear;
}
div:hover {
width: 300px;
}
</style>
</head>
<body>
Hover cursor over the box
<div></div>
</body>
3. Mixed transition
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: pink;
transition-delay: 0s;
transition-duration: 2s;
transition-property: width background-color border-radius;
transition-timing-function: linear;
}
div:hover {
width: 300px;
background-color: black;
border-radius: 50%;
}
</style>
</head>
<body>
Hover cursor over the box
<div></div>
</body>
Animations
Add animation in CSS
@keyframes example {
from {background-color: red;}
to {background-color: yellow;}
}
</style>
</head>
<body>
<div></div>
<p><b>Note:</b> Go to original state after finished.</p>
</body>
2. Infinite animation, with 2 seconds delay at start
This animation runs for 4 seconds
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
position: relative;
animation-name: example;
animation-duration: 4s;
animation-delay: 2s;
animation-iteration-count: infinite;
}
@keyframes example {
0% {background-color:red; left:0px; top:0px;}
25% {background-color:yellow; left:200px; top:0px;}
50% {background-color:blue; left:200px; top:200px;}
75% {background-color:green; left:0px; top:200px;}
100% {background-color:red; left:0px; top:0px;}
}
</style>
</head>
<body>
<h1>Infinite Moving Animation</h1>
<div></div>
</body>
3. Shorthand
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
position: relative;
animation: example 4s infinite ease-in-out;
}
@keyframes example {
0% {background-color:red; left:0px; top:0px;}
25% {background-color:yellow; left:200px; top:0px;}
50% {background-color:blue; left:200px; top:200px;}
75% {background-color:green; left:0px; top:200px;}
100% {background-color:red; left:0px; top:0px;}
}
</style>
</head>
<body>
<h1>Infinite Moving Animation</h1>
<div></div>
</body>
4. Mixed Mode: Transition, Transform and Animation
<head>
<style>
div {
margin: 100px 100px;
height: 100px;
width: 100px;
border: 1px solid transparent;
transition: 1s linear;
background-color: red;
animation: example 1s infinite linear;
border-radius: 30%;
}
h1 {
animation: text 1s infinite linear;
}
@keyframes text {
0% {
background-image: radial-gradient(red, orange, yellow);
}
25% {
background-image: radial-gradient(lime, greenyellow, green);
}
50% {
background-image: radial-gradient(teal, turquoise, skyblue);
}
75% {
background-image: radial-gradient(royalblue, blue, mediumblue);
}
100% {
background-image: radial-gradient(red, orange, yellow);
}
}
@keyframes example {
0% {
background-image: radial-gradient(red, orange, yellow);
transform: rotate(0deg) scale(0.5);
}
25% {
background-image: radial-gradient(lime, greenyellow, green);
transform: rotate(90deg) scale(1.0);
}
50% {
background-image: radial-gradient(teal, turquoise, skyblue);
transform: rotate(180deg) scale(1.5);
}
75% {
background-image: radial-gradient(royalblue, blue, mediumblue);
transform: rotate(270deg) scale(1.0);
}
100% {
background-image: radial-gradient(red, orange, yellow);
transform: rotate(360deg) scale(0.5);
}
}
</style>
</head>
<body>
<h1><marquee>LET'S HAVE FUN</marquee></h1>
<div></div>
</body>