CSS Links
In this page:
a:link { property: value; }
a:visited { property: value; }
a:hover { property: value; }
a:active { property: value; }
Link States: hover, visited, active, focus
CSS pseudo-classes आपको किसी link को उसकी current state के आधार पर target करने देते हैं: :hover जब कोई mouse उसके ऊपर बैठा हो, :visited एक बार जब कोई visitor पहले उसे click कर चुका हो, :active click करने के exact moment के दौरान, और :focus जब उसे keyboard से select किया गया हो।
उदाहरण: Link States: hover, visited, active, focus
<style>
a:hover { color: red; }
a:visited { color: purple; }
a:active { color: orange; }
a:focus { outline: 2px solid blue; }
</style>
<a href="#">Interactive link</a>
सही Pseudo-Class Order
क्योंकि CSS बराबर specificity होने पर बाद वाले rules को पहले वाले rules पर लागू करता है, link pseudo-classes को एक साथ सही तरीके से काम करने के लिए एक specific order में लिखना ज़रूरी है: :link, :visited, :hover, फिर :active।
उदाहरण: The Correct Pseudo-Class Order
<style>
a:link { color: blue; }
a:visited { color: purple; }
a:hover { color: red; }
a:active { color: orange; }
</style>
<a href="#">LVHA order: link, visited, hover, active</a>
Hover पर Underline
एक common, subtle pattern है links को default रूप से बिना underline के रखना, फिर सिर्फ hover पर एक दिखाना, जो सामान्य पढ़ने को cluttered किए बिना interactivity का एक संतोषजनक हिस्सा देता है।
उदाहरण: Underline on Hover
<style>
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
<a href="#">Underline appears only on hover</a>
Links को Buttons की तरह Style करना
किसी link को plain text जैसा दिखना ज़रूरी नहीं, background, padding, और border-radius जोड़ना इसे एक असली button जैसा दिखा और महसूस करा सकता है, जबकि यह अंदर से फिर भी एक normal link की तरह ही behave करता है।
उदाहरण: Styling Links as Buttons
<style>
a.button {
background: royalblue;
color: white;
padding: 10px 20px;
border-radius: 6px;
}
</style>
<a href="#" class="button">Get Started</a>
Links पर Accessible Focus Styles
buttons और inputs की तरह ही, links को keyboard से focus होने पर एक साफ़ visible style चाहिए, ताकि page में tab करता हुआ कोई व्यक्ति हमेशा बता सके कि इस समय कौन-सा link selected है।
उदाहरण: Accessible Focus Styles on Links
<style>
a:focus {
outline: 3px solid orange;
outline-offset: 2px;
}
</style>
<a href="#">Tab to me to see a clear focus style</a>
- link pseudo-class rules को गलत order में लिखना, जो बाद की states को असल में कभी लागू न होने का कारण बन सकता है।
- :hover को style करना लेकिन :focus भूल जाना, जिससे keyboard users को mouse users जितना ही visual feedback नहीं मिलता।
- links से पूरी visual distinction हटा देना, जिससे visitors के लिए एक नज़र में यह बताना मुश्किल हो जाता है कि क्या clickable है।
- Links की अपनी अलग states होती हैं: :link, :visited, :hover, :active, और :focus, जिनमें से हर एक को अपने आप style किया जा सकता है।
- pseudo-class order के लिए एक common memory aid है 'LoVe HAte': link, visited, hover, active।
- Links को background, padding, और border-radius इस्तेमाल करके buttons जैसा style किया जा सकता है, सिर्फ plain underlined text की तरह नहीं।
यहाँ बताई गई सभी standard link pseudo-classes हर modern browser में supported हैं।
Chapter Quiz — Complete all 10 topics to unlock
0/10 topics done
Complete these topics first: