Menu

Related Topics

HTML CSS JavaScript PHP Node.js React.js C C++ Go Rust Swift Python Java Excel MS Word PowerPoint
Search

CSS pseudo classes in Hindi

CSS Pseudo Classes का उपयोग किसी HTML element की किसी particular state, position या condition को target करने के लिए किया जाता है। इनकी मदद से हम element की स्थिति के अनुसार अलग-अलग styling apply कर सकते हैं।

उदाहरण के लिए, जब user किसी button पर mouse लेकर जाता है, किसी input field में typing करने के लिए उसे select करता है, किसी checkbox को select करता है या किसी list में किसी particular position वाले item को target करना होता है, तब pseudo classes बहुत useful होती हैं।

Pseudo class को CSS selector के साथ : colon लगाकर लिखा जाता है, जैसे :hover, :focus और :first-child।

1. :hover

:hover pseudo class तब apply होती है जब user किसी element के ऊपर pointer लेकर जाता है। इसका use buttons, links, cards, navigation items और अन्य interactive elements में बहुत common है।

उदाहरण के लिए, किसी button पर mouse ले जाने पर उसका background color और text color बदल सकते हैं।

CSS
Code copied!

जब user button पर pointer लेकर जाएगा, तब button:hover वाला CSS rule apply होगा और button का background green हो जाएगा।

:hover का use website में visual feedback देने के लिए किया जाता है, जिससे user को पता चलता है कि कोई element interactive है।

2. :focus

:focus pseudo class उस element को target करती है जो currently focus में है। यह खासतौर पर form elements जैसे input, textarea और select के साथ useful है।

जब user किसी input पर click करता है या keyboard से Tab key दबाकर उस element तक पहुँचता है, तो वह focus state में आ सकता है।

CSS
Code copied!

ऊपर :focus की मदद से focused input की border blue की गई है। outline: none; default focus outline को हटाता है, लेकिन real websites में focus indicator को पूरी तरह हटाने के बजाय कोई स्पष्ट alternative focus style रखना accessibility के लिए बेहतर होता है।

3. :visited

:visited pseudo class उन links को target करती है जिन्हें browser के हिसाब से user पहले visit कर चुका है। इसका use visited और unvisited links की appearance को अलग करने के लिए किया जा सकता है।

CSS
Code copied!

इस example में normal link blue दिखाई देगा और visited link purple दिखाई दे सकता है। Browsers privacy reasons की वजह से :visited के साथ कुछ CSS properties को restrict करते हैं।

4. :first-child

:first-child pseudo class किसी parent element के पहले child को target करती है। इसका use तब useful होता है जब हमें किसी list, menu या container के first item को अलग style देना हो।

CSS
Code copied!

ऊपर ul के अंदर जो पहला li है, उस पर red color और bold styling apply होगी।

5. :last-child

:last-child pseudo class किसी parent element के आखिरी child को target करती है। यह :first-child के opposite situation में useful होती है।

CSS
Code copied!

इस example में list का आखिरी li bold और dark blue दिखाई देगा।

6. :nth-child(n)

:nth-child() एक powerful pseudo class है जिसकी मदद से parent के children में किसी particular position वाले element को target किया जा सकता है। इसमें specific number, odd, even और mathematical patterns का use किया जा सकता है।

CSS
Code copied!

even का use करके even-numbered rows को target किया जा सकता है, जबकि odd से odd-numbered rows को target किया जा सकता है। Tables में alternate row colors देने के लिए यह technique काफी useful है।

Specific position के लिए उदाहरण के रूप में li:nth-child(3) केवल तीसरे child को target कर सकता है।

7. :not(selector)

:not() pseudo class उन elements को select करने के लिए use होती है जो दिए गए selector से match नहीं करते। इसलिए इसे कभी-कभी exclusion selector के रूप में समझना आसान होता है।

CSS
Code copied!

ऊपर .special class वाले paragraphs को छोड़कर बाकी matching p elements पर gray color apply होगा।

8. :checked

:checked pseudo class उन form controls को target करती है जो currently selected या checked state में हों। इसका use checkbox और radio button जैसे controls के साथ किया जाता है।

CSS
Code copied!

जब checkbox checked होगा, तब selector input[type="checkbox"]:checked match करेगा। इसके आधार पर checkbox की appearance या उससे जुड़े दूसरे elements की styling बदली जा सकती है।

9. :disabled और :enabled

:disabled उन form elements को target करता है जो disabled या inactive state में होते हैं। इसके opposite में :enabled उन form elements को target करता है जो enabled और usable state में होते हैं।

CSS
Code copied!

इसका use forms में बहुत useful होता है। उदाहरण के लिए disabled input को gray background देकर user को visually बताया जा सकता है कि वह field currently available नहीं है।

CSS Pseudo Classes का Combined Example

अब एक practical example देखते हैं जिसमें कई pseudo classes को एक ही HTML page में use किया गया है। इसमें :hover, :visited, :focus, :checked, :disabled और :nth-child() जैसी pseudo classes को combine किया गया है।

HTML + CSS
Code copied!

इस combined example में अलग-अलग user interactions और element states के आधार पर styling बदलती है। उदाहरण के लिए input पर focus करने पर border बदलती है, submit button पर hover करने पर उसका background बदलता है, checkbox select करने पर उसके label की styling बदलती है और list की even items को अलग background मिलता है।

CSS Pseudo Classes के फायदे

Pseudo Classes और Pseudo Elements में अंतर

Pseudo Class किसी element की state, condition या position को target करती है, जबकि Pseudo Element किसी element के किसी specific part या generated content को target करने के लिए use होता है।

Feature Pseudo Class Pseudo Element
Syntax : से शुरू होती है आमतौर पर :: से शुरू होता है
Use State या condition target करना Element के specific part को target करना
Examples :hover, :focus, :checked ::before, ::after, ::first-letter

Note: CSS Pseudo Classes से आप बिना JavaScript के कई interactive और state-based styling effects बना सकते हैं। ये खासतौर पर forms, buttons, lists और links के साथ useful होती हैं।

Related Questions (FAQ in Hindi)

  1. CSS में Pseudo Classes और Pseudo Elements में क्या फर्क होता है?
  2. :hover को mobile devices पर कैसे handle किया जाता है?
  3. क्या हम multiple pseudo classes एक ही selector पर use कर सकते हैं?
  4. :nth-child() और :nth-of-type() में क्या अंतर होता है?
  5. क्या :checked pseudo class केवल checkboxes के लिए है?
  6. Pseudo classes का उपयोग accessibility बढ़ाने में कैसे किया जा सकता है?

Code copied!

Page Views
0
Visit ID
Not tracked yet
Visit Time
-
Time on Page
0 seconds

Request


Leave a Comment


INITIALIZING...


INITIALIZING...


Quizzes in Hindi

GK Online Quiz in Hindi 10 pages
HTML Online Quiz in Hindi 10 pages
CSS Online Quiz in Hindi 10 pages
JavaScript Online Quiz in Hindi 10 pages
CCC Online Quiz in Hindi 10 pages
History Online Quiz in Hindi 10 pages



Comments Total: 0 comments

📰 Latest Articles

Total: 0 Articles

Featured Products

0 Products 0 Loaded 0 Remaining

All Products Loaded!

You've reached the end of our collection.

Contact Us Form