Create simple CSS modal window - html

The goal is to create a simple and CSS-only modal window (popup), when the user clicks a link.
With no dependencies or any kind of script, and with as less code as possible.

.box {
width: 40%;
margin: 0 auto;
background: rgba(255,255,255,0.2);
padding: 35px;
border: 2px solid #fff;
border-radius: 20px/50px;
background-clip: padding-box;
text-align: center;
}
.overlay {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.7);
transition: opacity 500ms;
visibility: hidden;
opacity: 0;
}
.overlay:target {
visibility: visible;
opacity: 1;
}
.popup {
margin: 70px auto;
padding: 20px;
background: #fff;
border-radius: 5px;
width: 30%;
position: relative;
transition: all 5s ease-in-out;
}
.popup .close {
position: absolute;
top: 20px;
right: 30px;
transition: all 200ms;
font-size: 30px;
font-weight: bold;
text-decoration: none;
color: #333;
}
<div class="box">
<a class="button" href="#popup1">Open</a>
</div>
<div id="popup1" class="overlay">
<div class="popup">
<h2>Here i am</h2>
<a class="close" href="#">×</a>
</div>
</div>

I created this simple modal window:
.exit-intent {
opacity: 0;
visibility: hidden;
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
text-align: center;
background-color: rgba(255, 255, 255, .8);
z-index: 7;
display: flex;
flex-direction: column;
height: 100vh;
overflow-y: auto
}
.exit-intent {
position: fixed;
max-width: 500px;
border-radius: 10px;
background: rgba(255, 255, 255, 0.9);
visibility: hidden;
opacity: 0;
z-index: 1;
}
.exit-intent:target {
visibility: visible;
opacity: 1;
}
.exit-intent-close {
position: absolute;
max-width: 500px;
border-radius: 10px;
background: rgba(255, 255, 255, 0.9);
}
.exit-intent .close {
position: absolute;
right: 5px;
top: 5px;
padding: 5px;
color: #000;
font-size: 2em;
line-height: 0.6em;
font-weight: bold;
}
.exit-intent .close:hover {
color: #999;
}
.close-exit-intent {
background: rgba(0, 0, 0, 0.7);
cursor: default;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
opacity: 0;
visibility: hidden;
}
.exit-intent:target+.close-exit-intent {
opacity: 1;
visibility: visible;
}
Link
<div id="exit-intent" class="exit-intent">
×
<h2>Window</h2>
</div>

Related

CSS popup - safari issues

ive got a CSS popup box on my website targeted through an achor tag, it work perfectly fine in chrome and firefox but it wont open in safari, i think its something to do with the visibilty:hidden? any help would be great thanks heres a sample of the code :
<a href="#popup1" class="button">
</a>
<div id="popup1" class="overlay">
<div class="popup">
<h2>Main Stage</h2>
<a class="close" href="#">×</a>
<div class="content">content here</div>
</div>
</div>
CSS:
.button {
font-size: 1em;
padding: 10px;
color: #fff;
border: 2px solid #06D85F;
border-radius: 20px/50px;
text-decoration: none;
cursor: pointer;
transition: all 0.3s ease-out;
}
.button:hover {
background: #06D85F;
}
.overlay {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.7);
transition: opacity 500ms;
visibility: hidden;
opacity: 0;
}
.overlay:target {
visibility: visible;
opacity: 1;
}
.popup {
margin: 70px auto;
padding: 20px;
background: $blue;
width: 50%;
position: relative;
transition: all 1s ease-in-out;
}
Try this model
Only HTML CSS
$("#open").on('click',function (){
$('#model').fadeIn(800);
});
$("#closebtn").on('click',function (){
$('#model').fadeOut(800);
});
#model{
background : rgba(0,0,0,0.7);
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 100;
display: none;
}
#modelmain{
background: #fff;
width: 30%;
position: relative;
top: 20%;
left: calc(50% - 15%);
padding: 15px;
border-right: 4px;
border-radius: 5px;
}
#closebtn{
background-color: red;
color: white;
width: 30px;
height: 30px;
line-height: 30px;
text-align: center;
border-radius: 50%;
position: absolute;
top: -15px;
right: -15px;
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="open">Open model</button>
<div id="model">
<div id="modelmain">
<h2>Your Contain</h2>
<div id="closebtn">X</div>
</div>
</div>

Animation transition for modal

This is my html modal code
<div class="modal">
<div class="modal-body">
</div>
</div>
<div class="modal-background"></div>
This is my CSS
modal {
position: fixed;
top: 53px;
right: 0;
bottom: 0;
left: 0;
z-index: 1000;
overflow: auto;
transition: opacity 0.4s, bottom 0.4s;
opacity: 1;
.modal-body {
padding-left: 70px;
background: #fff;
border: 0;
border-bottom-left-radius: 1rem;
border-bottom-right-radius: 1rem;
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}
}
.modal-background {
position: fixed;
top: 55px;
right: 0;
bottom: 0;
left: 0;
background-color: #000;
opacity: 0.75;
z-index: 900;
}
}
body.modal-open {
overflow: hidden;
}
I have tried to add slide down animation transition when open modal, but i dont know why this didn't work, can someone help me?. Thanks in advance

How should these CSS classes be positioned?

How would you position these CSS classes?
I'm talking about the order from 1st to last. Top to bottom.
Starting with .wrap, ending with .hide.
I just readjusted all of these classes, but which would be a good way line these up?
All help would be greatly appreciated.
Something like this?
https://jsfiddle.net/49ajbhte/35/
<div class="wrape">
<div class="covere" title="OPEN"></div>
<ul class="nav">
.wrape {
position: relative;
width: 266px;
height: 174px;
margin-top: 8px;
overflow: hidden;
}
.covere {
width: 266px;
height: 174px;
background: url("https://i.imgur.com/dCneQvW.png") no-repeat 0 0;
cursor: pointer;
border: 3px solid #0059dd;
box-sizing: border-box;
}
.covere {
display: none;
}
.inactivee .covere {
display: block;
}
.covere::before,
.covere::after {
content: "";
position: absolute;
top: 0;
left: 86px;
width: 3px;
height: 100%;
background: #0059dd;
}
.covere::after {
left: 177px;
}
.nav {
margin: 0;
padding: 0;
list-style: none;
}
.nav li {
float: left;
}
.nav a {
float: left;
width: 50px;
height: 50px;
margin: 0 4px 12px 0;
color: transparent;
background: rgba(0, 0, 0, .2);
border: 3px solid #0059dd;
box-sizing: border-box;
}
.nav a:hover {
border: 3px solid red;
}
.nav li:nth-of-type(5n) a {
margin-right: 0;
}
.nav li:nth-of-type(8) a {
opacity: 0;
}
.nav li:nth-of-type(15) a {
position: relative;
border: 3px solid #0059dd;
background: none;
}
.left-background {
position: absolute;
top: 0;
left: 0;
width: 12px;
height: 100%;
background: rgba(0, 255, 255, 0.5);
}
.left-border {
position: absolute;
top: 0;
left: 12px;
width: 3px;
height: 100%;
background: #0059dd;
}
.middle-background {
position: absolute;
top: 0;
left: 15px;
width: 14px;
height: 100%;
background: rgba(255, 255, 255, 0.5);
}
.right-border {
position: absolute;
top: 0;
left: 29px;
width: 3px;
height: 100%;
background: #0059dd;
}
.right-background {
position: absolute;
top: 0;
left: 32px;
width: 12px;
height: 100%;
background: rgba(255, 0, 255, 0.5);
}
.inactivee a {
display: none;
}
.inactivee .playButtone {
display: none;
}
.activee .playButtone {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: auto;
width: 50px;
height: 50px;
background: rgba(0, 0, 0, .7);
cursor: pointer;
fill: #aaff00;
}
.activee {
background: url("https://i.imgur.com/dCneQvW.png") no-repeat -260px 0;
}
.playe,
.pausee {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 6px;
margin: auto;
}
.pausee {
left: 0;
}
.hide {
display: none;
}
or like this:
https://jsfiddle.net/49ajbhte/33/
<div class="wrape">
<div class="covere" title="OPEN"></div>
<ul class="nav">
.wrap {
position: relative;
width: 266px;
height: 174px;
margin-top: 8px;
overflow: hidden;
}
.nav a {
float: left;
width: 50px;
height: 50px;
margin: 0 4px 12px 0;
color: transparent;
background: rgba(0, 0, 0, .2);
border: 3px solid #0059dd;
box-sizing: border-box;
}
.nav a:hover {
border: 3px solid red;
}
.nav li:nth-of-type(5n) a {
margin-right: 0;
}
.nav li:nth-of-type(8) a {
opacity: 0;
}
.nav li:nth-of-type(15) a {
position: relative;
border: 3px solid #0059dd;
background: none;
}
.nav li:nth-of-type(15) a {
position: relative;
border: 3px solid #0059dd;
background: none;
}
.left-background {
position: absolute;
top: 0;
left: 0;
width: 12px;
height: 100%;
background: rgba(0, 255, 255, 0.5);
}
.left-border {
position: absolute;
top: 0;
left: 12px;
width: 3px;
height: 100%;
background: #0059dd;
}
.middle-background {
position: absolute;
top: 0;
left: 15px;
width: 14px;
height: 100%;
background: rgba(255, 255, 255, 0.5);
}
.right-border {
position: absolute;
top: 0;
left: 29px;
width: 3px;
height: 100%;
background: #0059dd;
}
.right-background {
position: absolute;
top: 0;
left: 32px;
width: 12px;
height: 100%;
background: rgba(255, 0, 255, 0.5);
}
.inactivee a {
display: none;
}
.inactivee .playButtone {
display: none;
}
.covere {
width: 266px;
height: 174px;
background: url("https://i.imgur.com/dCneQvW.png") no-repeat 0 0;
cursor: pointer;
border: 3px solid #0059dd;
box-sizing: border-box;
}
.covere {
display: none;
}
.inactivee .covere {
display: block;
}
.covere::before,
.covere::after {
content: "";
position: absolute;
top: 0;
left: 86px;
width: 3px;
height: 100%;
background: #0059dd;
}
.covere::after {
left: 177px;
}
.nav {
margin: 0;
padding: 0;
list-style: none;
}
.nav li {
float: left;
}
.activee .playButtone {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: auto;
width: 50px;
height: 50px;
background: rgba(0, 0, 0, .7);
cursor: pointer;
fill: #aaff00;
}
.activee {
background: url("https://i.imgur.com/dCneQvW.png") no-repeat -260px 0;
}
.playe,
.pausee {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 6px;
margin: auto;
}
.pausee {
left: 0;
}
.hide {
display: none;
}
According to the html
This comes first
.wrape {
position: relative;
width: 266px;
height: 174px;
margin-top: 8px;
overflow: hidden;
}
Then Cover:
.covere {
width: 266px;
height: 174px;
background: url("https://i.imgur.com/dCneQvW.png") no-repeat 0 0;
cursor: pointer;
border: 3px solid #0059dd;
box-sizing: border-box;
}
Then these would come right before the 'a' anchor tag.
.nav {
margin: 0;
padding: 0;
list-style: none;
}
.nav li {
float: left;
}
Then the 'a' anchor tags would come next:
.nav a {
float: left;
width: 50px;
height: 50px;
margin: 0 4px 12px 0;
color: transparent;
background: rgba(0, 0, 0, .2);
border: 3px solid #0059dd;
box-sizing: border-box;
}
.nav a:hover {
border: 3px solid red;
}
.nav li:nth-of-type(5n) a {
margin-right: 0;
}
.nav li:nth-of-type(8) a {
opacity: 0;
}
.nav li:nth-of-type(15) a {
position: relative;
border: 3px solid #0059dd;
background: none;
}
.left-background {
position: absolute;
top: 0;
left: 0;
width: 12px;
height: 100%;
background: rgba(0, 255, 255, 0.5);
}
.left-border {
position: absolute;
top: 0;
left: 12px;
width: 3px;
height: 100%;
background: #0059dd;
}
.middle-background {
position: absolute;
top: 0;
left: 15px;
width: 14px;
height: 100%;
background: rgba(255, 255, 255, 0.5);
}
.right-border {
position: absolute;
top: 0;
left: 29px;
width: 3px;
height: 100%;
background: #0059dd;
}
.right-background {
position: absolute;
top: 0;
left: 32px;
width: 12px;
height: 100%;
background: rgba(255, 0, 255, 0.5);
}
Then these would come next? but I have no idea why.
.wrape.inactivee a {
display: none;
}
.wrape.inactivee .playButtone {
display: none;
}
Then these would come after that.
.activee .playButtone {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: auto;
width: 50px;
height: 50px;
background: rgba(0, 0, 0, .7);
cursor: pointer;
fill: #aaff00;
}
.activee {
background: url("https://i.imgur.com/dCneQvW.png") no-repeat -260px 0;
}
.playe,
.pausee {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 6px;
margin: auto;
}
.pausee {
left: 0;
}
.hide {
display: none;
}
Both of those work and wont effect your code. However, the first one will keep you from getting lost in your code. Its always good to arrange your html the same as your CSS.

CSS styled checkbox not working when clicked

Index.html
<div class="wrap">
<div class="toggle">
<input type="checkbox" onclick='window.location.assign("newuser.html")'/>
<span class="btn"></span>
<span class="texts"></span>
<span class="bg"></span>
</div>
</div>
Index.css
#import url(http://fonts.googleapis.com/css? family=Open+Sans:400,600|Lato:300,400,700&subset=latin,cyrillic);
* {
margin: 0;
padding: 0;
}
body {
background: #ecf0f1;
}
.wrap {
width: 90px;
margin: 50px auto;
}
.toggle {
position: relative;
width: 82px;
height: 35px;
border: 3px solid #f9f9f9;
border-radius: 40px;
}
.toggle input[type="checkbox"] {
opacity: 0;
cursor: pointer;
position: absolute;
top: 0;
left: 0;
z-index: 10;
width: 84px;
height: 34px;
}
.toggle .btn {
display: block;
position: absolute;
z-index: 4;
top: -3px;
left: -1px;
width: 37px;
height: 37px;
background: #F5F5F5;
border: 1px solid #e8e8e8;
border-radius: 100%;
box-shadow: 0 2px 4px rgba(100, 100, 100, 0.1);
transition: left .25s ease-in-out;
}
.toggle input[type="checkbox"]:checked ~ .btn {
left: 44px;
}
.toggle .texts {
position: absolute;
top: 9px;
z-index: 2;
width: 100%;
font-family: 'Lato', Helvetica, sans-serif;
font-weight: bold;
color: #fff;
text-transform: uppercase;
font-size: 14px;
}
.toggle .texts:before {
content: "On";
position: absolute;
left: 12px;
}
.toggle .texts:after {
content: "Off";
position: absolute;
right: 11px;
}
.toggle .bg {
display: block;
background: #F56557;
position: absolute;
z-index: 0;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 40px;
box-shadow: inset 0 0px 2px 1px rgba(0, 0, 0, 0.3);
transition: background .25s ease-in;
}
.toggle input[type="checkbox"]:checked ~ .bg {
background: #48C893;
}
I am creating an Android mobile application and I ran this code in Eclipse Luna. I managed to show the button but when it is clicked, nothing happens.
Your code is working. The style is changed onclick.
The problem might be somewhere else
* {
margin: 0;
padding: 0;
}
body {
background: #ecf0f1;
}
.wrap {
width: 90px;
margin: 50px auto;
}
.toggle {
position: relative;
width: 82px;
height: 35px;
border: 3px solid #f9f9f9;
border-radius: 40px;
}
.toggle input[type="checkbox"] {
opacity: 0;
cursor: pointer;
position: absolute;
top: 0;
left: 0;
z-index: 10;
width: 84px;
height: 34px;
}
.toggle .btn {
display: block;
position: absolute;
z-index: 4;
top: -3px;
left: -1px;
width: 37px;
height: 37px;
background: #F5F5F5;
border: 1px solid #e8e8e8;
border-radius: 100%;
box-shadow: 0 2px 4px rgba(100, 100, 100, 0.1);
transition: left .25s ease-in-out;
}
.toggle input[type="checkbox"]:checked ~ .btn {
left: 44px;
}
.toggle .texts {
position: absolute;
top: 9px;
z-index: 2;
width: 100%;
font-family: 'Lato', Helvetica, sans-serif;
font-weight: bold;
color: #fff;
text-transform: uppercase;
font-size: 14px;
}
.toggle .texts:before {
content: "On";
position: absolute;
left: 12px;
}
.toggle .texts:after {
content: "Off";
position: absolute;
right: 11px;
}
.toggle .bg {
display: block;
background: #F56557;
position: absolute;
z-index: 0;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 40px;
box-shadow: inset 0 0px 2px 1px rgba(0, 0, 0, 0.3);
transition: background .25s ease-in;
}
.toggle input[type="checkbox"]:checked ~ .bg {
background: #48C893;
}
<div class="wrap">
<div class="toggle">
<input type="checkbox" />
<span class="btn"></span>
<span class="texts"></span>
<span class="bg"></span>
</div>
</div>
Look into the below jsfiddle for your code
your onClick might be faster that your vision
your code seems working fine please check from your end

How can I achieve this hover effect?

I am currently reverse building this website, everything else works ok, however,I cannot find a way to achieve the photo hover effect like it does.
http://www.lovelytemplates.com/viewdemo/Snaps
And here is my code, can anyone advise me where did I do wrong?
img {
width: 236px;
height: 314px;
}
div:hover {
opacity: 0.9;
color: #fff;
background: rgba(0, 0, 0, 0.9);
}
<div>
<img src="http://demo.graphpaperpress.com/snaps/files/2013/04/child-72305-480x640.jpg" alt="" />asdfasdf asd
</div>
Give this a try? I didn't look at how the original site did it. Quite possibly there's a better way:
img {
width: 236px;
height: 314px;
position: absolute;
}
div.overlay {
width: 236px;
height: 314px;
position: absolute;
background-color: black;
color: white;
display: none;
line-height: 314px;
font-family: Arial;
text-align: center;
}
div.container:hover div.overlay {
width: 236px;
height: 314px;
background-color: rgba(0, 0, 0, 0.8);
display: block;
}
<div class="container">
<img src="http://demo.graphpaperpress.com/snaps/files/2013/04/child-72305-480x640.jpg" alt="">
<div class="overlay">
Text goes here.
</div>
</div>
You can easily do it this way. I have used a combination of:
opacity
translateY
position
div {
position: relative;
display: inline-block;
}
img {
width: 236px;
height: 314px;
opacity: .8
}
div:hover img,
div:hover .caption {
opacity: 1;
color: #fff;
background: rgba(0, 0, 0, 0.5);
}
.caption {
position: absolute;
z-index: 999;
top: 0; bottom: 0;
right: 0; left: 0;
background: rgba(0,0,0,0.5);
opacity: 0;
}
.caption span {
top: 50%;
right: 0; left: 0;
transform: translateY(-50%);
color: #fff;
text-align: center;
display: block;
position: absolute;
}
<div>
<img src="http://demo.graphpaperpress.com/snaps/files/2013/04/child-72305-480x640.jpg" alt="" />
<div class="caption"><span>Hello World</span></div>
</div>
try this for exact same effect on hover
.title {
font-size: 8em;
font-weight: bold;
text-shadow: 7px 7px 0 rgba(0, 0, 0, 0.5);
text-transform: uppercase;
font-family: sans-serif;
color: #fff;
opacity: 0.8;
}
.title :hover {
opacity: 1;
}