I will use a hidden checkbox, some sibling combinators and CSS3's :checked pseudo class to do the magic. The buttons to show and dismiss are only labels for the checkbox. Click on the button below to show the dialog:
The CSS for the actual display of the dialog and opaque background:
/** if nothing else do not show the dialog container */
.expand, .bg {
display: none;
}
/** an .expand class immediately following a checked checkbox */
/** this will show the dialog container when the checkbox is checked */
input.check:checked + .expand {
position: fixed;
top: 0px; bottom:0px; left: 0px; right: 0px;
z-index: 10;
display: block !important;
}
/** a .bg class that follows (not necessarily immediately) a checked checkbox */
/** this is the opaque background layer. active when the dialog is visible. */
input.check:checked ~ .bg {
position: fixed;
top: 0px; bottom:0px; left: 0px; right: 0px;
opacity: 0.5;
background-color: black;
z-index: 9;
display: block !important;
}
/** do not show the checkbox that holds the visibility state of the dialog */
input.check {
display: none;
}
We used the direct sibling combinator (+) for the .expand class and the general sibling combinator (~) for the background. We could have also used the general one for both. The general matches any sibling, while the direct only the sibling right next to the checkbox.
The code above could be made a little more compact by merging the .expand and .bg common parts.
All the rest of the CSS is to make the dialog look a little like a dialog.
No comments:
Post a Comment