CSS Pointer Events
In this page:
selector {
pointer-events: auto | none;
}
none Value
pointer-events: none किसी element को pointer interaction tree से पूरी तरह हटा देता है, इसलिए clicks और hovers इसके through उसके नीचे stacked किसी भी element तक चले जाते हैं।
- buttons के अंदर रखे decorative icons पर pointer-events: none इस्तेमाल करें ताकि icon पर hover करना अभी भी सही तरीके से button पर hover करने की तरह register हो।
- Accepted values:
- auto — normal pointer behavior (default)
- none — element pointer events नज़रअंदाज़ करता है और उन्हें through जाने देता है
- SVG-only values — visiblePainted, fill, stroke, all
- inherit | initial | unset | revert — हर property द्वारा accepted CSS-wide keywords
उदाहरण: The none Value
<style>
.icon {
pointer-events: none;
}
</style>
<button><span class="icon">🔍</span> Search</button>
auto Value
pointer-events: auto standard interactive behavior restore करता है और ज़्यादातर elements के लिए default है, लेकिन यह खासतौर पर किसी parent के अंदर एक child को दोबारा enable करने के लिए उपयोगी हो जाता है जिस पर pointer-events: none लागू है।
- एक otherwise non-interactive disabled overlay के अंदर एक specific close button पर pointer-events: auto इस्तेमाल करें ताकि सिर्फ वही एक action available रहे।
- Accepted values:
- auto — normal mouse और touch behavior (initial value)
- none — element pointer events नज़रअंदाज़ करता है
- visiblePainted | visibleFill | visibleStroke | visible | painted | fill | stroke | all — SVG-specific values
- inherit | initial | unset | revert — हर property द्वारा accepted CSS-wide keywords
उदाहरण: The auto Value
<style>
.disabled-overlay {
pointer-events: none;
background: rgba(0,0,0,0.4);
padding: 20px;
}
.close-btn {
pointer-events: auto;
}
</style>
<div class="disabled-overlay">
<button class="close-btn">Close (still works)</button>
</div>
किसी Element पर Clicks Disable करना
pointer-events: none किसी interactive-looking element को layout से हटाए या hide किए बिना visually disable करने का एक lightweight तरीका है, disabled attribute के उलट जो सिर्फ form controls पर लागू होता है।
- buttons की तरह act करने वाले custom clickable divs के लिए, pूरी तरह disabled appearance के लिए pointer-events: none को reduced opacity और cursor: not-allowed के साथ combine करें।
- Accepted values:
- auto — normal mouse और touch behavior (initial value)
- none — element pointer events नज़रअंदाज़ करता है
- visiblePainted | visibleFill | visibleStroke | visible | painted | fill | stroke | all — SVG-specific values
- inherit | initial | unset | revert — हर property द्वारा accepted CSS-wide keywords
उदाहरण: Disabling Clicks on an Element
<style>
.fake-disabled {
pointer-events: none;
opacity: 0.5;
cursor: not-allowed;
background: lightgray;
padding: 12px;
}
</style>
<div class="fake-disabled">Visually disabled without the disabled attribute</div>
Overlay Elements
Full page overlays, जैसे modal backdrops या loading screens, को अक्सर अपने नीचे की हर चीज़ के साथ interaction block करने की ज़रूरत होती है जबकि वे खुद clickable रहें, icon pattern से उल्टा use case।
उदाहरण: Overlay Elements
<style>
.backdrop {
position: fixed;
inset: 0;
background: rgba(0,0,0,0.5);
color: white;
pointer-events: auto;
}
</style>
<div class="backdrop">Clickable, so clicking it can close the modal</div>
SVG पर pointer-events
pointer-events originally एक SVG-only property थी जिसमें visiblePainted और all जैसी अतिरिक्त values थीं, यह control करते हुए कि fill, stroke, या bounding box areas pointer interaction को respond करें या नहीं।
उदाहरण: pointer-events on SVG
<svg width="100" height="100">
<circle cx="50" cy="50" r="40" fill="lightblue" stroke="steelblue" stroke-width="2" pointer-events="all"></circle>
</svg>
- किसी पूरे disabled form पर pointer-events: none set करना बिना यह realize किए कि यह screen reader interaction cues भी block करता है, हमेशा इसे aria-disabled के साथ जोड़ें।
- यह भूल जाना कि एक child element pointer-events: auto restore करके फिर से clickable बन सकता है भले ही उसके parent ने pointer-events: none set किया हो।
- किसी button को disable करने के इकलौते तरीके के रूप में pointer-events: none इस्तेमाल करना, जो button को keyboard से focus और activate होने से नहीं रोकता।
- pointer-events: none किसी element को visually present रखते हुए mouse और pointer interactions के लिए invisible बना देता है।
- pointer-events: auto default है और normal interactivity restore करता है, किसी disabled parent के अंदर किसी specific child को दोबारा enable करने के लिए उपयोगी।
- pointer-events: all किसी SVG element को उसकी fill या stroke visibility चाहे जो भी हो हमेशा pointer events को respond करने पर मजबूर करता है।
pointer-events हर modern browser में सभी elements पर supported है; non-SVG HTML elements पर support SVG support से थोड़ी बाद में आया लेकिन अब universal है।
Chapter Quiz — Complete all 22 topics to unlock
0/22 topics done
Complete these topics first:
- CSS Combinators
- CSS Pseudo-classes
- CSS Pseudo-elements
- CSS Opacity
- CSS Navigation Bar
- CSS Vertical Navbar
- CSS Horizontal Navbar
- CSS Dropdowns
- CSS Advanced Dropdowns
- CSS Image Gallery
- CSS Image Sprites
- CSS Attribute Selectors
- CSS Forms
- CSS Counters
- CSS Specificity
- CSS Specificity Hierarchy
- CSS Variables
- CSS !important
- CSS Box Sizing
- CSS Media Queries
- CSS Pointer Events
- CSS Outline