{"id":161,"date":"2016-09-25T08:20:15","date_gmt":"2016-09-25T08:20:15","guid":{"rendered":"http:\/\/jtc-art.com\/code-blog\/?p=161"},"modified":"2016-09-25T08:20:15","modified_gmt":"2016-09-25T08:20:15","slug":"simple-responsive-pop-modal-box","status":"publish","type":"post","link":"https:\/\/jtc-art.com\/code-blog\/simple-responsive-pop-modal-box\/","title":{"rendered":"Code Demo for Simple Responsive Pop Up Modal Box"},"content":{"rendered":"<p>Here is the basic code. First, I make a wrapper with the ID \u201cpopUp\u201d. Inside I add a fixed div with 100% width, 100% height and a transparent background using rgba(0, 0, 0, 0.5). In the rgba code the first 3 spaces set the color (rgb) and the last space sets the opacity (1 being full opacity). So now I have a dark transparent background. Next I add the pop up box\/modal. I give this a height and width. I set the top and left attributes to 50%. Then I give a negative value for the top and left margins. I set these to minus half of the width and half of the height of the box. Width = minus 300px\/2 (-150px). And the same with the top.<\/p>\n<h2><strong>CSS:<\/strong><\/h2>\n<pre>#popUp {\r\n  display: none;\r\n}\r\n#popUpBg {\r\nwidth: 100%;\r\nheight: 100%;\r\nposition: fixed;\r\nbackground-color: rgba(0, 0, 0, 0.5);\r\nz-index: 10;\r\ntop: 0;\r\nleft: 0;\r\ndisplay: block;\r\n}\r\n\r\n#popUpBox {\r\ndisplay: block;\r\nposition: fixed;\r\nwidth: 300px;\r\nheight: 250px;\r\ntop: 50%;\r\nleft: 50%;\r\nmargin: -125px 0 0 -150px;\r\nbackground: #FFFFFF;\r\nborder: solid 3px #ed1c24;\r\nz-index: 20;\r\ntext-align: center;\r\nbox-shadow: 0 0 20px #222222;\r\n}\r\n\r\n#popUpBox p {\r\nfont-size: 2.2em;\r\nfont-weight: bold;\r\npadding: 40px 20px;\r\nline-height: 1.2;\r\nmargin: 0;\r\n}\r\n\r\n#popUpBox a.button {\r\nfont-size: 1.4em;\r\nfont-weight: bold;\r\nbackground: #ed1c24;\r\npadding: 10px 30px;\r\nborder-radius: 5px;\r\ncolor: #FFFFFF;\r\ntext-decoration: none;\r\ndisplay: inline-block;\r\n}\r\n<\/pre>\n<h2>HTML:<\/h2>\n<pre>&lt;div id=\"popUp\"&gt;\r\n  &lt;div id=\"popUpBg\"&gt;&amp;nbsp;&lt;\/div&gt;\r\n  &lt;div id=\"popUpBox\"&gt;\r\n    &lt;p&gt;Important Message...&lt;\/p&gt;\r\n    &lt;a id=\"popUpOk\" class=\"button\" href=\"javascript:;\"&gt;OK&lt;\/a&gt;\r\n  &lt;\/div&gt;\r\n&lt;\/div&gt;\r\n&lt;a class=\"openPopUp\" href=\"javascript:;\"&gt;Open Pop Up&lt;\/a&gt;<\/pre>\n<p>Lastly, I add some jQuery to animate the box. When the page loads the code adds onclick events to the pop up background, the ok\/close button and the \u201cOpen Pop Up\u201d link.<\/p>\n<h2>jQuery:<\/h2>\n<pre>$(document).ready(function() {\r\n  $(\".openPopUp\").click(function() {\r\n    $(\"#popUp\").show()\r\n  });\r\n  $(\"#popUpBg\").click(function() {\r\n    $(\"#popUp\").hide()\r\n  });\r\n  $(\"#popUpOk\").click(function() {\r\n    $(\"#popUp\").hide()\r\n  });\r\n});<\/pre>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/jsfiddle.net\/jtcampbellart\/6wu1co93\/\" target=\"_blank\">See a demo on Fiddle<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is the basic code. First, I make a wrapper with the ID \u201cpopUp\u201d. Inside I add a fixed div with 100% width, 100% height and a transparent background using rgba(0, 0, 0, 0.5). In the rgba code the first 3 spaces set the color (rgb) and the last space sets the opacity (1 being &hellip; <a href=\"https:\/\/jtc-art.com\/code-blog\/simple-responsive-pop-modal-box\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Code Demo for Simple Responsive Pop Up Modal Box<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-161","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Code Demo for Simple Responsive Pop Up Modal Box - Code Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jtc-art.com\/code-blog\/simple-responsive-pop-modal-box\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Code Demo for Simple Responsive Pop Up Modal Box - Code Blog\" \/>\n<meta property=\"og:description\" content=\"Here is the basic code. First, I make a wrapper with the ID \u201cpopUp\u201d. Inside I add a fixed div with 100% width, 100% height and a transparent background using rgba(0, 0, 0, 0.5). In the rgba code the first 3 spaces set the color (rgb) and the last space sets the opacity (1 being &hellip; Continue reading Code Demo for Simple Responsive Pop Up Modal Box &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jtc-art.com\/code-blog\/simple-responsive-pop-modal-box\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Blog\" \/>\n<meta property=\"article:published_time\" content=\"2016-09-25T08:20:15+00:00\" \/>\n<meta name=\"author\" content=\"Jason Campbell\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jason Campbell\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/simple-responsive-pop-modal-box\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/simple-responsive-pop-modal-box\\\/\"},\"author\":{\"name\":\"Jason Campbell\",\"@id\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/#\\\/schema\\\/person\\\/2ecb375f4b2fdd46b424aa06c592a85b\"},\"headline\":\"Code Demo for Simple Responsive Pop Up Modal Box\",\"datePublished\":\"2016-09-25T08:20:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/simple-responsive-pop-modal-box\\\/\"},\"wordCount\":172,\"commentCount\":0,\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/simple-responsive-pop-modal-box\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/simple-responsive-pop-modal-box\\\/\",\"url\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/simple-responsive-pop-modal-box\\\/\",\"name\":\"Code Demo for Simple Responsive Pop Up Modal Box - Code Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/#website\"},\"datePublished\":\"2016-09-25T08:20:15+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/#\\\/schema\\\/person\\\/2ecb375f4b2fdd46b424aa06c592a85b\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/simple-responsive-pop-modal-box\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/simple-responsive-pop-modal-box\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/simple-responsive-pop-modal-box\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Code Demo for Simple Responsive Pop Up Modal Box\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/#website\",\"url\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/\",\"name\":\"Code Blog\",\"description\":\"The Code Blog of Jason T Campbell\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/#\\\/schema\\\/person\\\/2ecb375f4b2fdd46b424aa06c592a85b\",\"name\":\"Jason Campbell\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a4a4c7111068f877b9afce9f62af6b28c85f862d9cbe6d194eaaf3c83939766f?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a4a4c7111068f877b9afce9f62af6b28c85f862d9cbe6d194eaaf3c83939766f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a4a4c7111068f877b9afce9f62af6b28c85f862d9cbe6d194eaaf3c83939766f?s=96&d=mm&r=g\",\"caption\":\"Jason Campbell\"},\"url\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/author\\\/jasonc\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Code Demo for Simple Responsive Pop Up Modal Box - Code Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jtc-art.com\/code-blog\/simple-responsive-pop-modal-box\/","og_locale":"en_US","og_type":"article","og_title":"Code Demo for Simple Responsive Pop Up Modal Box - Code Blog","og_description":"Here is the basic code. First, I make a wrapper with the ID \u201cpopUp\u201d. Inside I add a fixed div with 100% width, 100% height and a transparent background using rgba(0, 0, 0, 0.5). In the rgba code the first 3 spaces set the color (rgb) and the last space sets the opacity (1 being &hellip; Continue reading Code Demo for Simple Responsive Pop Up Modal Box &rarr;","og_url":"https:\/\/jtc-art.com\/code-blog\/simple-responsive-pop-modal-box\/","og_site_name":"Code Blog","article_published_time":"2016-09-25T08:20:15+00:00","author":"Jason Campbell","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Jason Campbell","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jtc-art.com\/code-blog\/simple-responsive-pop-modal-box\/#article","isPartOf":{"@id":"https:\/\/jtc-art.com\/code-blog\/simple-responsive-pop-modal-box\/"},"author":{"name":"Jason Campbell","@id":"https:\/\/jtc-art.com\/code-blog\/#\/schema\/person\/2ecb375f4b2fdd46b424aa06c592a85b"},"headline":"Code Demo for Simple Responsive Pop Up Modal Box","datePublished":"2016-09-25T08:20:15+00:00","mainEntityOfPage":{"@id":"https:\/\/jtc-art.com\/code-blog\/simple-responsive-pop-modal-box\/"},"wordCount":172,"commentCount":0,"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jtc-art.com\/code-blog\/simple-responsive-pop-modal-box\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jtc-art.com\/code-blog\/simple-responsive-pop-modal-box\/","url":"https:\/\/jtc-art.com\/code-blog\/simple-responsive-pop-modal-box\/","name":"Code Demo for Simple Responsive Pop Up Modal Box - Code Blog","isPartOf":{"@id":"https:\/\/jtc-art.com\/code-blog\/#website"},"datePublished":"2016-09-25T08:20:15+00:00","author":{"@id":"https:\/\/jtc-art.com\/code-blog\/#\/schema\/person\/2ecb375f4b2fdd46b424aa06c592a85b"},"breadcrumb":{"@id":"https:\/\/jtc-art.com\/code-blog\/simple-responsive-pop-modal-box\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jtc-art.com\/code-blog\/simple-responsive-pop-modal-box\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jtc-art.com\/code-blog\/simple-responsive-pop-modal-box\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jtc-art.com\/code-blog\/"},{"@type":"ListItem","position":2,"name":"Code Demo for Simple Responsive Pop Up Modal Box"}]},{"@type":"WebSite","@id":"https:\/\/jtc-art.com\/code-blog\/#website","url":"https:\/\/jtc-art.com\/code-blog\/","name":"Code Blog","description":"The Code Blog of Jason T Campbell","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jtc-art.com\/code-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/jtc-art.com\/code-blog\/#\/schema\/person\/2ecb375f4b2fdd46b424aa06c592a85b","name":"Jason Campbell","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/a4a4c7111068f877b9afce9f62af6b28c85f862d9cbe6d194eaaf3c83939766f?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a4a4c7111068f877b9afce9f62af6b28c85f862d9cbe6d194eaaf3c83939766f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a4a4c7111068f877b9afce9f62af6b28c85f862d9cbe6d194eaaf3c83939766f?s=96&d=mm&r=g","caption":"Jason Campbell"},"url":"https:\/\/jtc-art.com\/code-blog\/author\/jasonc\/"}]}},"_links":{"self":[{"href":"https:\/\/jtc-art.com\/code-blog\/wp-json\/wp\/v2\/posts\/161","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jtc-art.com\/code-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jtc-art.com\/code-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jtc-art.com\/code-blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jtc-art.com\/code-blog\/wp-json\/wp\/v2\/comments?post=161"}],"version-history":[{"count":1,"href":"https:\/\/jtc-art.com\/code-blog\/wp-json\/wp\/v2\/posts\/161\/revisions"}],"predecessor-version":[{"id":162,"href":"https:\/\/jtc-art.com\/code-blog\/wp-json\/wp\/v2\/posts\/161\/revisions\/162"}],"wp:attachment":[{"href":"https:\/\/jtc-art.com\/code-blog\/wp-json\/wp\/v2\/media?parent=161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jtc-art.com\/code-blog\/wp-json\/wp\/v2\/categories?post=161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jtc-art.com\/code-blog\/wp-json\/wp\/v2\/tags?post=161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}