NEW! 竞彩体育平台 by TapClicks - SEO + SEM Tools with Deeper Competitive Insights

GET STARTED FREE External Link Tap Click Logo Tap Click Logo

The 竞彩体育平台 Blog

We write tips for digital marketers and we create beginner through advanced guides for search engine optimization. Improve your SEO and Content Marketing game.


Written by and published

Back in my early programming days, before I switched over to web development, I spent most of my time writing software for Windows. I look back on that time with fond memories. 8-bit icons , OLE2 , and no silly Start menus .

With the recent Web 2.0 boom, many web developers have returned to their roots and begun building sites that resemble desktop applications. AJAX (the second coming of javascript) lets designers borrow elements from the desktop paradigm and use them on their websites.

One element that I find myself using quite a bit are modal dialogs . In a desktop application, a modal dialog is a box or message that forces you to dismiss it before you can use any other part of the program. When used sparingly, it can be a great way to direct the user’s attention to a specific element and force them to make a decision. With a little CSS and Javascript we can accomplish this same effect on the web.

Measure the impact of your design changes on your site’s performance with 竞彩体育平台 ’s Site Auditor , rank tracking and  Google Analytics  integration. Sign up for a  free 14 day trial  of 竞彩体育平台 Tools and get started in minutes.

The code behind this effect is surprisingly simple. There are three pieces involved:

  • A
    containing the content you want to appear when the modal area is activated.
  • Two CSS rules which keep the layer hidden until needed and then “fullscreen” when activated.
  • Javascript which hides and shows the

The overlay

At the bottom of your HTML, create a

with id = “overlay”. Any content placed inside this area will initially be hidden by the browser and then shown modally when activated. Any content beneath it will be “unclickable” by the user, which forces them to interact with whatever message you give them.

Inside #overlay I usually place another

which I center horizontally and apply a few styles to create a dialog box appearance. It’s this second
that actually contains the content I’m showing the user.


Content you want the user to see goes here.


There’s only one CSS rule to take care of the fullscreen/hiding for #overlay.

																#overlay { visibility: hidden; position: absolute; left: 0px; top: 0px; width:100%; height:100%; text-align:center; z-index: 1000; }

You can style the inner

however you like. As I said above, I usually center it horizontally to give it more of a dialog box look and feel.

																	#overlay div { width:300px; margin: 100px auto; background-color: #fff; border:1px solid #000; padding:15px; text-align:center; }

The Javascript

The javascript that controls everything is insanely simple. Just add the following function to wherever you’re storing your javascript. (That could be in the of your document or in an external .js file.)

																		function overlay() { el = document.getElementById("overlay"); = ( == "visible") ? "hidden" : "visible"; }

The javascript grabs our overlay element and then toggles its visibility property. If it’s hidden, it makes it visible and vice versa. You could create a function to explicitly show or hide the layer, but I prefer this automatic toggle method since it requires less code.

With the function in place, we then call it whenever we want to show the overlay and then again to hide it. So, somewhere on our page we could add

																			Click here to show the overlay

When the user clicks on the link our javascript will show the overlay.

Within the overlay’s HTML, we need to add a link to hide it. The code is exactly the same:

																		Click here to [

Finishing Touches

When the user clicks the link to show the overlay, they may become confused since it looks like they can still click on any element in the page. To help them understand what’s going on, we can apply a background image to the overlay

. In Photoshop I create a simple checkerboard pattern .png with transparency. This creates a shaded effect so the user can still see the underlying web page but know not to click on it. To add the background to the layer, add the following to our CSS.

																			#overlay { visibility: hidden; position: absolute; left: 0px; top: 0px; width:100%; height:100%; text-align:center; z-index: 1000;

And finally, (as always) we need to add a small tweak so that this works in Internet Explorer. Fortunately, it’s quick fix. Add this to your CSS.

																			body { height:100%; margin:0; padding:0; }

In order for an element to have a percentage height applied to it (which #overlay does), IE requires the parent element to have a height. So, just set body’s height to 100% and zero the margins and we’re all set!


Reader Henrik Binggl commented that this technique doesn’t work on form elements in IE6. I did some digging and found an article on MSDN that explains the problem, which, as it turns out, only applies to

(No spam. Just knowledge.)

thank you for subscribing !

"Nah, I don't like learning"
体育电竞手机版入口 英雄联盟竞猜下注下载网 竞博电竞积分赛事 极速电竞直播安卓下载网站 英雄联盟竞猜排榜APP v2.0 pc加拿大28计划分析最稳网页