Pseudo-classes define special states of an element.
Example:
a:hover { color: red; } /* Mouse hover */
input:focus { border: 2px solid blue; }
Pseudo-classes define special states of an element.
Example:
a:hover { color: red; } /* Mouse hover */
input:focus { border: 2px solid blue; }
relative
→ positioned relative to normal flow.absolute
→ positioned relative to its parent container.fixed
→ fixed to viewport (doesn’t move on scroll).sticky
→ behaves like relative, but sticks when scrolling.<style>
in the HTML <head>
..css
file (best practice).CSS (Cascading Style Sheets) is used to style and format HTML elements (colors, fonts, layouts, responsiveness)
p { color: blue; font-size: 18px; }
<!DOCTYPE html>
<html>
<head>
<style>
img {
width: 200px;
border-radius: 15px; /* Rounded edges */
box-shadow: 4px 4px 10px rgba(0,0,0,0.5);
transition: transform 0.3s;
}
img:hover {
transform: scale(1.1); /* Zoom effect */
}
</style>
</head>
<body>
<img src="https://via.placeholder.com/200" alt="Example">
</body>
</html>
Explanation:
border-radius
: softens corners.box-shadow
: adds shadow.hover
+ scale
: zooms image when hovered.<!DOCTYPE html>
<html>
<head>
<style>
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr); /* 3 equal columns */
gap: 10px;
}
.grid div {
background: lightcoral;
padding: 20px;
text-align: center;
}
</style>
</head>
<body>
<div class="grid">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
</div>
</body>
</html>
Explanation:
display: grid;
arranges items into a grid.grid-template-columns: repeat(3, 1fr);
makes 3 equal columns.gap
: space between items.<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
background: #333;
overflow: hidden;
padding: 0;
margin: 0;
}
li {
float: left;
}
li a {
display: block;
color: white;
padding: 14px 20px;
text-decoration: none;
}
li a:hover {
background: #111;
}
</style>
</head>
<body>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
</body>
</html>
Explanation:
ul
+ li
.hover
effect changes background color when mouse is over.<!DOCTYPE html>
<html>
<head>
<style>
.circle {
width: 150px;
height: 150px;
background: orange;
border-radius: 50%; /* Makes perfect circle */
text-align: center;
line-height: 150px;
color: white;
font-weight: bold;
}
</style>
</head>
<body>
<div class="circle">Circle</div>
</body>
</html>
Explanation:
border-radius: 50%
creates a circle.10px
just make rounded corners.<!DOCTYPE html>
<html>
<head>
<style>
h1 {
text-shadow: 2px 2px 5px gray; /* X, Y, blur, color */
}
.box {
width: 200px;
height: 100px;
background: lightgreen;
box-shadow: 5px 5px 15px rgba(0,0,0,0.3);
text-align: center;
line-height: 100px;
}
</style>
</head>
<body>
<h1>Text Shadow Example</h1>
<div class="box">Box Shadow</div>
</body>
</html>
Explanation:
text-shadow
: adds a glowing or shadow effect to text.box-shadow
: adds shadow around elements.<!DOCTYPE html>
<html>
<head>
<style>
.gradient {
width: 300px;
height: 150px;
background: linear-gradient(to right, red, yellow);
text-align: center;
line-height: 150px;
font-weight: bold;
color: white;
}
</style>
</head>
<body>
<div class="gradient">Gradient Background</div>
</body>
</html>
Explanation:
linear-gradient(to right, red, yellow)
creates a smooth color transition.to bottom
, to left
, to top right
, etc.