cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <!-- should work IE11+ -->
<!-- Buggy in edge but still usable -->
<div class="wrap">
  <h1>Testing fixed positioned close icon on fixed positioned modal</h1>
  <p><button class="open">Open Modal</button></p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <p>content to scroll</p>
  <div class="modal">
    <!-- uses auto positions so first make sure element in the normal flow is where you need it to be and then at that point make the child fixed positioned -->
    <button class="close"><span><b>&times;</b></span></button>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas rutrum felis diam, sed tempor sapien convallis id. Phasellus id urna nec magna eleifend suscipit. Vivamus eget aliquam nunc. Etiam dignissim bibendum enim a maximus. Nullam pulvinar cursus urna vulputate luctus. In bibendum turpis nec ante dapibus, vel consectetur velit hendrerit. Vivamus convallis justo nec lacinia placerat. Morbi dolor lorem, egestas eget ex vel, ultricies vulputate mauris. Donec eget nisl eget lectus pretium congue eget ut metus. Sed pharetra facilisis lectus nec posuere. Donec vulputate, nulla sed maximus pretium, sapien urna porta mauris, id dictum leo metus id elit. Sed ornare tempor ultrices. Maecenas volutpat libero quis tempus blandit.</p>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas rutrum felis diam, sed tempor sapien convallis id. Phasellus id urna nec magna eleifend suscipit. Vivamus eget aliquam nunc. Etiam dignissim bibendum enim a maximus. Nullam pulvinar cursus urna vulputate luctus. In bibendum turpis nec ante dapibus, vel consectetur velit hendrerit. Vivamus convallis justo nec lacinia placerat. Morbi dolor lorem, egestas eget ex vel, ultricies vulputate mauris. Donec eget nisl eget lectus pretium congue eget ut metus. Sed pharetra facilisis lectus nec posuere. Donec vulputate, nulla sed maximus pretium, sapien urna porta mauris, id dictum leo metus id elit. Sed ornare tempor ultrices. Maecenas volutpat libero quis tempus blandit.</p>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas rutrum felis diam, sed tempor sapien convallis id. Phasellus id urna nec magna eleifend suscipit. Vivamus eget aliquam nunc. Etiam dignissim bibendum enim a maximus. Nullam pulvinar cursus urna vulputate luctus. In bibendum turpis nec ante dapibus, vel consectetur velit hendrerit. Vivamus convallis justo nec lacinia placerat. Morbi dolor lorem, egestas eget ex vel, ultricies vulputate mauris. Donec eget nisl eget lectus pretium congue eget ut metus. Sed pharetra facilisis lectus nec posuere. Donec vulputate, nulla sed maximus pretium, sapien urna porta mauris, id dictum leo metus id elit. Sed ornare tempor ultrices. Maecenas volutpat libero quis tempus blandit.</p>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas rutrum felis diam, sed tempor sapien convallis id. Phasellus id urna nec magna eleifend suscipit. Vivamus eget aliquam nunc. Etiam dignissim bibendum enim a maximus. Nullam pulvinar cursus urna vulputate luctus. In bibendum turpis nec ante dapibus, vel consectetur velit hendrerit. Vivamus convallis justo nec lacinia placerat. Morbi dolor lorem, egestas eget ex vel, ultricies vulputate mauris. Donec eget nisl eget lectus pretium congue eget ut metus. Sed pharetra facilisis lectus nec posuere. Donec vulputate, nulla sed maximus pretium, sapien urna porta mauris, id dictum leo metus id elit. Sed ornare tempor ultrices. Maecenas volutpat libero quis tempus blandit.</p>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas rutrum felis diam, sed tempor sapien convallis id. Phasellus id urna nec magna eleifend suscipit. Vivamus eget aliquam nunc. Etiam dignissim bibendum enim a maximus. Nullam pulvinar cursus urna vulputate luctus. In bibendum turpis nec ante dapibus, vel consectetur velit hendrerit. Vivamus convallis justo nec lacinia placerat. Morbi dolor lorem, egestas eget ex vel, ultricies vulputate mauris. Donec eget nisl eget lectus pretium congue eget ut metus. Sed pharetra facilisis lectus nec posuere. Donec vulputate, nulla sed maximus pretium, sapien urna porta mauris, id dictum leo metus id elit. Sed ornare tempor ultrices. Maecenas volutpat libero quis tempus blandit.</p>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas rutrum felis diam, sed tempor sapien convallis id. Phasellus id urna nec magna eleifend suscipit. Vivamus eget aliquam nunc. Etiam dignissim bibendum enim a maximus. Nullam pulvinar cursus urna vulputate luctus. In bibendum turpis nec ante dapibus, vel consectetur velit hendrerit. Vivamus convallis justo nec lacinia placerat. Morbi dolor lorem, egestas eget ex vel, ultricies vulputate mauris. Donec eget nisl eget lectus pretium congue eget ut metus. Sed pharetra facilisis lectus nec posuere. Donec vulputate, nulla sed maximus pretium, sapien urna porta mauris, id dictum leo metus id elit. Sed ornare tempor ultrices. Maecenas volutpat libero quis tempus blandit.</p>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas rutrum felis diam, sed tempor sapien convallis id. Phasellus id urna nec magna eleifend suscipit. Vivamus eget aliquam nunc. Etiam dignissim bibendum enim a maximus. Nullam pulvinar cursus urna vulputate luctus. In bibendum turpis nec ante dapibus, vel consectetur velit hendrerit. Vivamus convallis justo nec lacinia placerat. Morbi dolor lorem, egestas eget ex vel, ultricies vulputate mauris. Donec eget nisl eget lectus pretium congue eget ut metus. Sed pharetra facilisis lectus nec posuere. Donec vulputate, nulla sed maximus pretium, sapien urna porta mauris, id dictum leo metus id elit. Sed ornare tempor ultrices. Maecenas volutpat libero quis tempus blandit.</p>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas rutrum felis diam, sed tempor sapien convallis id. Phasellus id urna nec magna eleifend suscipit. Vivamus eget aliquam nunc. Etiam dignissim bibendum enim a maximus. Nullam pulvinar cursus urna vulputate luctus. In bibendum turpis nec ante dapibus, vel consectetur velit hendrerit. Vivamus convallis justo nec lacinia placerat. Morbi dolor lorem, egestas eget ex vel, ultricies vulputate mauris. Donec eget nisl eget lectus pretium congue eget ut metus. Sed pharetra facilisis lectus nec posuere. Donec vulputate, nulla sed maximus pretium, sapien urna porta mauris, id dictum leo metus id elit. Sed ornare tempor ultrices. Maecenas volutpat libero quis tempus blandit.</p>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas rutrum felis diam, sed tempor sapien convallis id. Phasellus id urna nec magna eleifend suscipit. Vivamus eget aliquam nunc. Etiam dignissim bibendum enim a maximus. Nullam pulvinar cursus urna vulputate luctus. In bibendum turpis nec ante dapibus, vel consectetur velit hendrerit. Vivamus convallis justo nec lacinia placerat. Morbi dolor lorem, egestas eget ex vel, ultricies vulputate mauris. Donec eget nisl eget lectus pretium congue eget ut metus. Sed pharetra facilisis lectus nec posuere. Donec vulputate, nulla sed maximus pretium, sapien urna porta mauris, id dictum leo metus id elit. Sed ornare tempor ultrices. Maecenas volutpat libero quis tempus blandit.</p>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas rutrum felis diam, sed tempor sapien convallis id. Phasellus id urna nec magna eleifend suscipit. Vivamus eget aliquam nunc. Etiam dignissim bibendum enim a maximus. Nullam pulvinar cursus urna vulputate luctus. In bibendum turpis nec ante dapibus, vel consectetur velit hendrerit. Vivamus convallis justo nec lacinia placerat. Morbi dolor lorem, egestas eget ex vel, ultricies vulputate mauris. Donec eget nisl eget lectus pretium congue eget ut metus. Sed pharetra facilisis lectus nec posuere. Donec vulputate, nulla sed maximus pretium, sapien urna porta mauris, id dictum leo metus id elit. Sed ornare tempor ultrices. Maecenas volutpat libero quis tempus blandit.</p>
  </div>
</div>
            
          
!
            
              html {
	box-sizing: border-box;
}
*, *:before, *:after {
	box-sizing: inherit;
}
html, body {
	margin:0;
	padding:0;
}
body {
	background:#666;
	color:#fff;
}
/* IE11 and edge need body to have scrolled before they will fix the close icon */
/* however when a modal is active it wiuld be better to stop any scrolling ion the body anyway */

body.modal-on {
	height:101vh;
	overflow:hidden;
}
/* 
or alternatively use either of these.

body{min-height:100.1vh;}

/* Nasty hack if you don't want a vertical scrollbar
_:-ms-lang(x),  body{min-height:100.1vh;}
*/

.wrap {
	display:table;
	max-width:980px;
	margin:auto;
	width:100%;
}
.modal {
	position:fixed;
	top:10%;
	bottom:10%;
	width:980px;
	left:calc((100vw - 980px)/2);/*stop jump when scrollbar disappears*/
	margin:auto;
	padding:40px 20px 20px;
	overflow:auto;
	background:#fff;
	color:#000;
	box-shadow:0 0 10px 10px rgba(0,0,0,0.5);
	border:5px solid red;
	display:none;
	z-index:999;
}
/* 
	ie11 doesn't do margin auto on max-width positioned elements so use media query instead
	This is nothing to do with the close icon technique 
*/
@media screen and (max-width:980px) {
.modal {
	width:auto;
	left:0;
}
}
.modal-on:before{
	content:"";
	position:fixed;
	left:0;
	top:0;
	right:0;
	bottom:0;
	background:rgba(0,0,0,0.7);
}

.close {
	-webkit-appearance:none;
	appearance:none;
	padding:0;
	margin:0;
	z-index:99;
	background:transparent;
	border:none;
	float:right;
	width:30px;
	height:30px;
	outline:0;
}
.close span {
	width:30px;
	height:30px;
	display:block;
	position:fixed;
}
.close b {
	position:relative;
	margin-top:-40px;
	display:block;
	border-radius:50%;
	background:#ccc;
	color:#f00;
	text-align:center;
	line-height:30px;
	border:1px solid #666;
	cursor:pointer;
  font-size:29px;
}
.close:focus b{border:1px solid red;}
            
          
!
            
              $(document).on('click','.open',function(){
	$('body').addClass('modal-on');
	$('.modal').fadeIn();
});

$("body" ).on( "click",".close", function() {
	$('body').removeClass('modal-on');
	$('.modal').fadeOut()
});

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console