Pure CSS PopUp Form Search
Pure CSS PopUp Form Search
by Adi Jaya
HTML
<label for="checkbox-search" aria-label="Toggle form Search" role="button" tabindex="0" class="button">
Click Me...
</label>
<p>Lorem</p>
<p>Ipsum</p>
<p>Dolor</p>
<input id="checkbox-search" type="checkbox"/>
<div id="search-container">
<label for="checkbox-search">
<span class="null-close">Close</span>
</label>
<div class="form-container">
<form>
<input class='input'
placeholder='Search..'
spellcheck='false'
/>
</form>
</div>
</div>
CSS
body {
margin: 16px;
font-family: sans-serif;
}
.button {
padding: 8px 12px;
border: 1px solid #0a3fca;
border-radius: 4px;
cursor: pointer;
line-height: 1;
background: blue;
color: #fff;
margin: 1em;
display: inline-block;
}
#checkbox-search {
display: none;
}
#search-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.83);
-webkit-transition: all 0.5s;
-o-transition: all 0.5s;
transition: all 0.5s;
-webkit-transform: scale(0);
-ms-transform: scale(0);
transform: scale(0);
visibility: hidden;
opacity: 0;
}
/*
#search-container.open for handle with js,
if css no support
*/
#checkbox-search:checked ~ #search-container,
#search-container.open {
-webkit-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
visibility: visible; /* CSS Web Safe browser */
opacity: 1;
}
/* Reference [visibility]
https://developer.mozilla.org/en-US/docs/Web/CSS/visibility#Browser_compatibility
https://caniuse.com/#search=visibility
*/
#search-container label {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 1;
}
.form-container {
position: relative;
top: 35%;
padding: 1em;
margin: 0 auto;
max-width: 600px;
z-index: 100;
}
.input {
display: block;
width: 100%;
background: transparent;
border: 0;
border-bottom: 1px solid #fff;
font-size: 200%;
color: #fff;
padding: 8px 0;
outline: none;
}
.null-close {
position: absolute;
right: 10px;
top: 10px;
color: #fff;
cursor: pointer;
}
JavaScript
/* if browser not support CSS [ :checked ~ selector ]
$( document ).on( "change", "#checkbox-search", function(){
var target = $( "#search-container" );
var checked = $( this );
if( checked.is( ":checked" ) ) {
target.addClass( "open" );
} else {
target.removeClass( "open" );
}
});
*/