CSS কী?
CSS-এর পূর্ণরূপ Cascading Style Sheets। HTML পেজের রং, আকার, জায়গা, layout, responsive design এবং animation তৈরি করতে CSS ব্যবহার হয়।
CSS Zero থেকে Hero। ব্যাখ্যা, code, live demo, practice, project এবং quiz—সব একটি offline ফাইলে।
CSS কী, HTML-এর সঙ্গে কীভাবে যুক্ত করবেন এবং প্রথম style লিখবেন।
CSS-এর পূর্ণরূপ Cascading Style Sheets। HTML পেজের রং, আকার, জায়গা, layout, responsive design এবং animation তৈরি করতে CSS ব্যবহার হয়।
h1, p, div, class ও id-এর সাধারণ HTML ব্যবহার জানলেই এই কোর্স শুরু করা যাবে।
index.html নামে একটি ফাইল বানান।<head>-এর ভিতরে <style> লিখুন।<!DOCTYPE html>
<html lang="bn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>আমার প্রথম CSS</title>
<style>
h1 {
color: blue;
text-align: center;
}
p {
font-size: 20px;
}
</style>
</head>
<body>
<h1>CSS শেখা শুরু</h1>
<p>এই লেখাটির আকার CSS দিয়ে পরিবর্তন হয়েছে।</p>
</body>
</html>Inline, Internal ও External CSS কোথায় এবং কখন ব্যবহার করবেন।
একটি element-এর জন্য style attribute। ছোট পরীক্ষা ছাড়া বড় project-এ এড়িয়ে চলুন।
একটি HTML পেজের <style>-এর ভিতরে CSS। এক পেজের demo-তে ভালো।
আলাদা style.css ফাইল। Professional project-এ সবচেয়ে ভালো পদ্ধতি।
<!-- 1. Inline -->
<h1 style="color: red;">Hello</h1>
<!-- 2. Internal: head-এর ভিতরে -->
<style>
h1 { color: green; }
</style>
<!-- 3. External: head-এর ভিতরে -->
<link rel="stylesheet" href="style.css">
/* style.css ফাইল */
h1 {
color: purple;
}CSS rule কীভাবে তৈরি হয় এবং element নির্বাচন করা হয়।
selector { property: value; }/* Element selector */
p {
color: #334155;
}
/* Class selector */
.card {
padding: 20px;
}
/* ID selector */
#hero {
min-height: 400px;
}
/* একাধিক selector */
h1, h2, h3 {
font-family: Arial, sans-serif;
}
/* ভেতরের element */
nav a {
text-decoration: none;
}
/* Direct child */
.menu > li {
display: inline-block;
}
/* Attribute selector */
input[type="email"] {
border-color: blue;
}
/* Universal selector */
* {
box-sizing: border-box;
}class সবচেয়ে বেশি ব্যবহার হয়।কোন CSS rule কাজ করবে এবং কেন অন্য rule হারিয়ে যায়।
একই শক্তির rule হলে পরে লেখা rule সাধারণত কাজ করে।
সাধারণভাবে Inline > ID > Class > Element selector।
color ও font-family-এর মতো কিছু property parent থেকে child-এ যায়।
p {
color: blue;
}
.message {
color: green;
}
#notice {
color: red;
}
/* HTML */
<p id="notice" class="message">এই লেখা লাল হবে</p>!important ব্যবহার করবেন না।রং, background image, opacity ও gradient নিয়ন্ত্রণ।
.one { color: red; }
.two { color: #2563eb; }
.three { color: rgb(37, 99, 235); }
.four { color: hsl(221, 83%, 53%); }
.hero {
color: white;
background-color: #1e293b;
background-image:
linear-gradient(135deg, rgba(37,99,235,.9), rgba(124,58,237,.9)),
url("hero.jpg");
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}px, %, rem, em, vw, vh, ch, min(), max() ও clamp()।
| Unit | ব্যবহার |
|---|---|
px | নির্দিষ্ট ছোট মাপ, border ইত্যাদি |
rem | Root font-size অনুযায়ী scalable spacing ও text |
% | Parent-এর তুলনায় মাপ |
vw/vh | Viewport width/height |
ch | লেখার line width |
html {
font-size: 16px;
}
.container {
width: min(92%, 1200px);
margin-inline: auto;
}
h1 {
font-size: clamp(2rem, 5vw, 4.5rem);
}
article {
max-width: 65ch;
}Font, line-height, alignment, decoration, overflow ও web font।
body {
font-family: system-ui, "Segoe UI", Arial, sans-serif;
font-size: 1rem;
line-height: 1.7;
color: #172033;
}
h1 {
font-size: clamp(2rem, 5vw, 4rem);
font-weight: 800;
letter-spacing: -0.03em;
line-height: 1.1;
text-align: center;
}
a {
color: #2563eb;
text-decoration-thickness: 2px;
text-underline-offset: 4px;
}
.one-line {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}line-height ও সীমিত line width পড়া সহজ করে।Content, padding, border, margin, width, height ও overflow।
/* সব project-এর শুরুতে */
*, *::before, *::after {
box-sizing: border-box;
}
.card {
width: 320px;
padding: 24px;
border: 2px solid #cbd5e1;
margin: 20px auto;
border-radius: 16px;
overflow: hidden;
}border-box দিলে width-এর ভিতরেই padding ও border গণনা হয়।Block, inline, hidden, sticky, absolute ও fixed element।
.inline-block {
display: inline-block;
}
.hidden {
display: none;
}
.header {
position: sticky;
top: 0;
z-index: 100;
}
.card {
position: relative;
}
.badge {
position: absolute;
top: 12px;
right: 12px;
}
.chat-button {
position: fixed;
right: 20px;
bottom: 20px;
}position: relative দিন।এক মাত্রার responsive layout, alignment, navigation ও card row।
.navbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
}
.cards {
display: flex;
flex-wrap: wrap;
gap: 1.5rem;
}
.card {
flex: 1 1 280px;
}দুই মাত্রার professional page ও card layout।
.gallery {
display: grid;
grid-template-columns:
repeat(auto-fit, minmax(min(100%, 240px), 1fr));
gap: 1.5rem;
}
.dashboard {
display: grid;
grid-template-columns: 240px minmax(0, 1fr);
min-height: 100vh;
}
.featured {
grid-column: span 2;
}Mobile-first website, breakpoints, responsive image ও container।
min-width media query দিন।.page {
width: min(92%, 1200px);
margin-inline: auto;
}
.layout {
display: grid;
gap: 1rem;
}
img {
max-width: 100%;
height: auto;
}
/* Tablet এবং বড় screen */
@media (min-width: 768px) {
.layout {
grid-template-columns: 260px 1fr;
}
}
/* Desktop */
@media (min-width: 1100px) {
.layout {
grid-template-columns: 280px 1fr 240px;
}
}Hover, focus, nth-child, before, after ও interactive state।
a:hover {
color: #7c3aed;
}
button:focus-visible,
input:focus-visible {
outline: 3px solid #93c5fd;
outline-offset: 3px;
}
input:invalid:not(:placeholder-shown) {
border-color: #dc2626;
}
.list li:nth-child(odd) {
background: #f8fafc;
}
.title::after {
content: "";
display: block;
width: 60px;
height: 4px;
margin-top: 8px;
background: currentColor;
}Professional input, button, card, table ও reusable component।
.form-group {
display: grid;
gap: .5rem;
margin-bottom: 1rem;
}
label {
font-weight: 700;
}
input, select, textarea {
width: 100%;
padding: .8rem 1rem;
border: 1px solid #cbd5e1;
border-radius: .75rem;
font: inherit;
}
input:focus, textarea:focus {
border-color: #2563eb;
outline: 3px solid #dbeafe;
}
.button {
display: inline-flex;
align-items: center;
justify-content: center;
gap: .5rem;
padding: .8rem 1.1rem;
border: 0;
border-radius: .75rem;
background: #2563eb;
color: white;
font-weight: 700;
cursor: pointer;
}
.button:hover {
background: #1d4ed8;
}Smooth interaction, loading animation এবং motion accessibility।
.card {
transition:
transform 200ms ease,
box-shadow 200ms ease;
}
.card:hover {
transform: translateY(-6px);
box-shadow: 0 18px 40px rgb(15 23 42 / 15%);
}
@keyframes spin {
to { transform: rotate(360deg); }
}
.loader {
animation: spin 800ms linear infinite;
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
scroll-behavior: auto !important;
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}Custom properties, calc, min/max/clamp, aspect-ratio ও object-fit।
:root {
--color-primary: #2563eb;
--color-text: #172033;
--space-1: .5rem;
--space-2: 1rem;
--radius: 1rem;
}
.button {
background: var(--color-primary);
padding: var(--space-1) var(--space-2);
border-radius: var(--radius);
}
.sidebar {
width: clamp(220px, 25vw, 320px);
}
.main {
min-height: calc(100vh - 72px);
}
.thumbnail {
aspect-ratio: 16 / 9;
width: 100%;
object-fit: cover;
}পরিষ্কার CSS file structure, BEM naming, reset এবং performance।
css/ ├── reset.css ├── variables.css ├── layout.css ├── components.css └── pages.css
.card, .card__title, .card--featured
/* 1. Reset */
*, *::before, *::after {
box-sizing: border-box;
}
body, h1, h2, h3, p {
margin: 0;
}
img, picture, video, canvas, svg {
display: block;
max-width: 100%;
}
/* 2. Base */
body {
min-height: 100vh;
font-family: system-ui, sans-serif;
line-height: 1.6;
}
/* 3. Layout */
.container {
width: min(92%, 1200px);
margin-inline: auto;
}
/* 4. Component */
.product-card { }
.product-card__title { }
.product-card--featured { }!important এবং একই style copy-paste।Style কেন কাজ করছে না তা বের করা এবং layout সমস্যা ঠিক করা।
outline: 2px solid red দিয়ে box দেখুন।/* শুধু debugging-এর সময় */
* {
outline: 1px solid rgb(255 0 0 / 20%);
}
.debug {
background: rgb(255 255 0 / 20%);
}শেখা যাচাই করার জন্য বাস্তব project এবং professional completion criteria।
ছবি, নাম, bio, social link, hover effect এবং responsive width।
Centered form, focus state, password field, button ও mobile layout।
CSS Grid, price badge, button, image ratio এবং card hover।
Navbar, hero, feature cards, testimonial, pricing ও footer।
Home, About ও Contact—একটি shared external stylesheet দিয়ে তৈরি করুন।
সবচেয়ে প্রয়োজনীয় property-এর দ্রুত তালিকা।
| বিষয় | Property | উদাহরণ |
|---|---|---|
| লেখার রং | color | color: #2563eb; |
| Background | background | background: #f8fafc; |
| Font size | font-size | font-size: 1.25rem; |
| ভেতরের জায়গা | padding | padding: 1rem; |
| বাইরের জায়গা | margin | margin: 0 auto; |
| Border | border | border: 1px solid #ddd; |
| গোল corner | border-radius | border-radius: 1rem; |
| ছায়া | box-shadow | box-shadow: 0 10px 30px #0002; |
| Flex | display | display: flex; |
| Grid | display | display: grid; |
| Alignment | justify-content | justify-content: center; |
| Responsive | @media | @media (min-width: 768px) { ... } |
নিজে উত্তর দিয়ে CSS জ্ঞান যাচাই করুন।