Basic Selectors
CSS selectors HTML element patterns ni match chesi styles apply chestayi. Correct selector choose cheyadam โ maintainable, scalable CSS foundation.
* { box-sizing: border-box; }
p { color: #333; }
.card { padding: 20px; }
#main-title { font-size: 2rem; }
a[href^="https"] { color: #2563eb; }
h1, h2, h3 { font-family: 'Sora', sans-serif; }
* โ page lo every element match avuthundi. CSS resets and global box-sizing ki common:
*, *::before, *::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
Tag name tho match โ p, h1, button, div:
p { color: #333; line-height: 1.7; }
button { cursor: pointer; border: none; }
Class selector most common and reusable. HTML lo class="card", CSS lo .card:
.card {
padding: 20px;
border-radius: 12px;
background: #fff;
box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
Naming conventions: kebab-case (.nav-link), BEM (.card__title--active), semantic names (.btn-primary not .blue-box).
ID unique ga undali page lo okate โ high specificity valla override cheyadam kashtam:
#main-title {
font-size: 2rem;
color: #1e293b;
}
Best practice: Styling ki classes prefer cheyandi. IDs JavaScript hooks and anchor links ki reserve cheyandi. Excessive IDs avoid cheyandi.
Grouping โ same styles multiple selectors ki:
h1, h2, h3 {
font-weight: 700;
color: #0f172a;
}
Attribute selectors:
input[type="email"] { border-color: #3b82f6; }
a[href^="https"] { font-weight: 600; }
img[alt=""] { outline: 2px dashed red; }
Case sensitivity: HTML class/ID names case-sensitive in quirks mode but standard mode lo case-sensitive. Always consistent casing use cheyandi.