Creating a Non-Modal Dialog with Highlight Effect
To create a non-modal dialog that's highlighted while the rest of the page appears dimmed (but still clickable), you can use a combination of CSS and HTML. Here's how to implement it:
HTML Structure
<div class="overlay"></div>
<div class="highlight-dialog">
<h2>Important Information</h2>
<p>This is a non-modal dialog. You can still interact with the page behind it.</p>
</div>
<!-- Rest of your page content -->
<button id="toggle-btn">Toggle Highlight Dialog</button>
CSS Styling
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
pointer-events: none; /* This makes it click-through */
z-index: 100;
display: none; /* Initially hidden */
}
.highlight-dialog {
position: static; /* Normal document flow */
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
margin: 20px;
z-index: 101; /* Above the overlay */
}
/* When active, we'll show the overlay */
.highlight-active .highlight-dialog {
position: relative; /* To ensure z-index works */
}
.highlight-active .overlay {
display: block;
}
JavaScript to Toggle
document.getElementById('toggle-btn').addEventListener('click', function() {
document.body.classList.toggle('highlight-active');
});
Alternative Pure CSS Solution
If you prefer a CSS-only approach (without JavaScript), you could use the :target pseudo-class:
<a href="#dialog" id="show-dialog">Show Dialog</a>
<a href="#" id="hide-dialog" style="display:none;">Hide Dialog</a>
<div class="overlay"></div>
<div id="dialog" class="highlight-dialog">
<h2>Important Information</h2>
<p>This is a non-modal dialog. You can still interact with the page behind it.</p>
<a href="#">Close</a>
</div>
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
pointer-events: none;
z-index: 100;
opacity: 0;
transition: opacity 0.3s;
}
#dialog:target ~ .overlay {
opacity: 1;
}
#dialog:target {
position: relative;
z-index: 101;
}
Key Points
- The overlay has
pointer-events: none which makes it click-through
- The dialog remains in normal document flow (
position: static)
- When active, we make the dialog
position: relative to ensure z-index works
- The overlay is semi-transparent to create the dimming effect
- The rest of the page remains fully interactive
You can adjust the colors, opacity, and positioning to match your design requirements.