How to make the modal CSS window. Create a modal window using HTML5 and CSS3. We will deal with the dimming

In this lesson, we learn how to create a modal window using HTML5 and CSS3. In the lesson, we will not use JS, only fully CSS3. Modal windows can be used for form feedbackFor photo and video and there are many options for its use.

We start making our modal window.

Step 1. HTML markup

First of all, we need to make HTML markup, i.e. Make a link to which window will open, and make the frame of our window. To do this, write this code:

Step 2. Content modal window

Now add the content itself of our window. We will make a title and a small text and put it all in the tag

and insert into the code instead of dots. You still need to insert a link on which our window will be closed and give it class \u003d "Close". This is how your code should look like:

REDStar project

Redstar - Project dedicated to questions that have been interested in so long ago. This project contains free lessons and articles on various topics. Themes are very diverse, ranging from simple windows installations And ending with the development of sites.

Step 3. Styles

Now we start writing styles for our window. In this step we will make an invisible window. It will only appear by clicking on the link. For this we write styles for our class modaldialog.:

Modaldialog (Position: Fixed; Font-Family: Arial, Helvetica, Sans-Serif; Top: 0; Right: 0; Bottom: 0; Left: 0; Background: RGBA (0,0,0,0,8); z-index : 99999; Opacity: 0; -WebKit-Transition: Opacity 400ms Ease-in; -moz-transition: Opacity 400ms Ease-in; Transition: Opacity 400ms Ease-in; Display: None; Pointer-Events: none;)

Step 4. Functional and viewing

In this step, we will make our window already start functioning. To do this, add a few more styles for our class. modaldialog.:

Modaldialog: Target (Opacity: 1; Pointer-Events: auto; display: block;) .modaldialog\u003e div (width: 400px; position: relative; margin: 10% auto; padding: 5px 20px 13px 20px; Border-Radius: 10px ; background: #FFF; Background: -moz-linear-gradient (#FFF, # B8ECFB); Background: -Webkit-linear-gradient (#FFF, # B8ECFB); Background: -O-Linear-gradient (#FFF, # B8ECFB);)

At this step you can already view your window, it is already functions. But, button close. It looks not very beautiful.

Now we need to add styles for our class close..

Step 5. We make the Close button

In this step we will improve appearance Our button that will close our window. For this we write styles for our class close.:

Close (background: # 606061; Color: #FFFFFF; Line-Height: 25px; position: absolute; right: -12px; text-align: center; top: -10px; width: 24px; text-decoration: none; font- Weight: Bold; -WebKit-Border-Radius: 12px; -Moz-Border-Radius: 12px; Border-Radius: 12px; -Moz-Box-Shadow: 1px 1px 3px # 000; -Webkit-Box-Shadow: 1px 1px 3px # 000; Box-shadow: 1px 1px 3px # 000;) .Close: Hover (Background: # 860015;)

Well, now our button looks like and thought. You should also look like:

This lesson is over. Thanks for attention! For your convenience, I added a demo version and source files. If, something is not clear, then download the source files.

Hello everyone, I will tell about one very comfortable thing, which is called a modal window, we will analyze how to make a modal window? Many do not understand what it is, I will try to explain the language that is clear for you, in other words, is a pop-up window when you click on the button or text.

Inside this window, there may be any information (video, picture, code, etc.) I now started using a modal window, as there is some kind of material that you need to say that it is not highlighted on the page and let's say, there was a picture, When you click on it, a window and information came up.

I recently did it on one site, I inserted a picture on the main thing, not even a picture and the screenshot from the video of YouTube, and when you click the window where the video shows. An example of such a window can be seen on my game page, the principle is the same, click on the picture pops up the window with the game. I did so much to the extension of the game more in width than I have a column for content, I found such a way out of the situation.

Consider the modal window on CSS, so as not to fool your head, we will use styles, then-there is pressing styles in the main file and code in our window, consider everything in detail what and how.

Modal window on CSS, how to make a modal window

The first thing we need is styles, copy a fully code with styles, which is lower and insert it into your main style file, then-there is in style.css

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 . Window (Position: Fixed; Font- Family: Arial, Helvetica, Sans- Serif; Top: 0; Right: 0; Bottom: 0; Left: 0; Background: RGBA (0, 0, 0, 0.7); z- index : 99999; - WebKit - Transition: OPACITY 400MS EASE- IN; - MOZ-TRANSTION: OPACITY 400MS EASE- IN; Transition: Opacity 400ms Ease- In; Display: None; Pointer- Events: none;). Window: Target (Display: Block; Pointer- events: auto;). Window\u003e DIV (Width: 460px; Position: relative; margin: 10% auto; padding: 30px 10px 10px; Border- Radius: 10px; Background: #FFF; Box- Shadow: 0px 0px 20px 2px;). Close (background: #FFFFFF; Line- Height: 25px; position: absolute; right: - 12px; text- align: center; top: - 10px; width: 24px; text- decoration: none; font- Weight: Bold; - WebKit- Border- Radius: 12px; - Moz- Border- Radius: 12px; Border- Radius: 12px; - Moz- Box - Shadow: 1px 1px 3px # 000; - WebKit- Box - Shadow: 1px 1px 3px # 000; Box- shadow: 1px 1px 3px # 000;). Close: Hover (Background: # 990000;)

Window (Position: Fixed; font-face: arial, helvetica, sans-serif; top: 0; right: 0; bottom: 0; left: 0; background: RGBA (0,0,0,0,0,7); z-index : 99999; -Webkit-transition: Opacity 400ms Ease-in; -MOZ-transition: Opacity 400ms Ease-in; Transition: Opacity 400ms Ease-in; Display: None; Pointer-Events: none;) .window: target (Display : block; Pointer-events: auto;) .window\u003e div (width: 460px; position: relative; margin: 10% auto; padding: 30px 10px 10px; border-radius: 10px; background: #FFF; Box-Shadow: 0px 0px 20px 2px;) .Close (color: #FFFFFFF; Line-Height: 25px; position: absolute; right: -12px; text-align: center; top: -10px; width: 24px; text -Decorage: none; font-weight: bold; -Webkit-Border-Radius: 12px; -Moz-Border-Radius: 12px; Border-Radius: 12px; -Moz-Box-Shadow: 1px 1px 3px # 000; -WebKit -Box-shadow: 1px 1px 3px # 000; Box-Shadow: 1px 1px 3px # 000;) .Close: Hover (Background: # 990000;)

We save, you can play with the styles, and something is more beautiful, change the background, the frame is different and so on. Go to the page where you want you to pop up this window, and insert the following code:

1 2 3 4 5 6 7 < a href= "#ModalOpen" title= "" > Button < div id= "ModalOpen" class = "Window" > < div> < a href= "#close" title= "Close" class = "close" > X. Here will be the contents of the window

Button

X here will be the contents of the window

Now we will analyze a little that in it, you need to change you. Where is spelled out "Button" There you can insert like a picture of Taiful text, in general what you want, then, when you click on it, a window will open. Where is spelled out there "Here will be the contents of the window" Insert the fact that you would like to see in the pop-up window, in principle, and that's it.

NEWS!

Well, on the track news as always, something I often became new)) I made a small page with partner ProgramIn the form, I will go to everyone to go to her and see, maybe someone will give some more advice as interesting, for example, something to supplement something, well, you understand what I'm talking about. There are still some thoughts on it, to add a video with me, can instruction, well, something like that, in general, I'm waiting for yourself comment!

Judging by the comments, the topic of creating modal windows is quite popular. I have already described various vending techniques as with using jQuery.and on pure CSS. And in the Internet, information on the topic is abused, and everyone can choose for themselves the optimal option.
I'm more interested in solutions without using javascript, not because I have some kind of phobia to JS, no, I'm just interested experiments, the search for new features of the HTML + CSS bundle, especially since these possibilities have recently expanded significantly.
Hidden Cheboks () I used a couple of times when developing, why not apply the same method and to implement pop-up (modal) windows. It turns out everything is quite simple, let's consider in more detail, as with the help of properties and new syntactic features, you can quickly and without much difficulties to organize the work of attractive modal windows on the pages of your sites.

Look a living example, test in different browsers and on various devicesMODAL windows fit perfectly into any sizes. In the example, it introduced three options for use, a standard dialog box, an integrated contact form and a built-in picture.

When forming an HTML framework of the modal window was guided by the principles of building a standard HTML page, i.e. Our window consists of a base container