<div class="wrap">
<a class="button" href="#openmodal"><span class="submit">Нажми</span> меня<span class="submit">!</span></a>
<div id="openmodal" class="modalbg">
<div class="dialog">
<a href="#close" title="Закрыть" class="close">X</a>
<h2>Привет Всем!!!</h2>
<p>Вы все же сделали это!</p>
<p>Вы открыли это модальное окно! Теперь нажмите на крестик, чтобы окно закрыть!</p>
<p class="fineprint">За основу взят урок "Модальные всплывающие окна с помощью CSS3 без Javascript" с блога <a href="http://dbmast.ru/modalnye-vsplyvayushhie-okna-s-pomoshhyu-css3-bez-javascript">Dobrovoimaster</a></p>
<p class="fineprint">p.s. К сожалению, не вовсех браузерах работает одинаково хорошо.</p>
</div>
</div>
</div>
CSS
body {
width: 100%;
background: url(http://subtlepatterns.subtlepatterns.netdna-cdn.com/patterns/grid.png) repeat #fefefe;
}
.wrap {
padding: 40px;
text-align: center;
}
/* Базовые стили затемнения и модального окна */
.modalbg {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
/* Цвет фона затемнения */
background: rgba(0, 0, 0, 0);
visibility: hidden;
z-index: 9999;
/* Устанавливаем эффект перехода */
-moz-transition: all 2s ease-out;
-webkit-transition: all 2s ease-out;
-o-transition: all 2s ease-out;
transition: all 2s ease-out;
-webkit-transition-delay: 0.2s;
-moz-transition-delay: 0.2s;
-o-transition-delay: 0.2s;
-transition-delay: 0.2s;
opacity: 0;
pointer-events: none;
}
/* Формируем блок с содержанием */
.dialog {
max-width: 400px;
font-family: Arial, Helvetica, sans-serif;
position: relative;
top: -1000px;
margin: 10% auto;
padding: 5px 20px 13px 20px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
/* Скругляем угы */
border-radius: 10px;
background: #fefefe;
/* Добавляем тени */
box-shadow: 0 0 10px #000000;
-moz-box-shadow: 0 0 10px #000000;
-webkit-box-shadow: 0 0 10px #000000;
z-index: 10000;
}
.modalbg:target {
opacity: 1;
visibility: visible;
pointer-events: auto;
background: rgba(4, 10, 30, 0.8);
/* Устанавливаем эффект перехода */
-moz-transition: all 0.5s ease-out;
-webkit-transition: all 0.5s ease-out;
-o-transition: all 0.5s ease-out;
transition: all 0.5s ease-out;
}
.modalbg:target .dialog {
top: 50px;
-moz-transition: all 0.4s ease-out;
-webkit-transition: all 0.4s ease-out;
-o-transition: all 0.4s ease-out;
transition: all 0.4s ease-out;
-webkit-transition-delay: 0.2s;
-moz-transition-delay: 0.2s;
-o-transition-delay: 0.2s;
-transition-delay: 0.2s;
}
/*** Кнопка закрытия ***/
.close {
background-color: rgba(61, 61, 61, 0.8);
border: 2px solid #ccc;
color: #FFFFFF;
line-height: 20px;
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.