How to Create a Simple CSS Popup in Your Web Page
Part 1 of 2:
Adding the Code
- Add this code inside the head tag of your web page:
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
- The above code will refer to the online library available. If your web page is not running online, then you must download the jquery library and link it to your webpage.
- Add the popup HTML code to your webpage. Make sure it's above the close body tag.
<body> <div> div> <div class="popup"> <div class="popupWindow"> <div class="popup_txt"> Are you 18 years of age or older? div> <div class="popup_img"> <img src="yes.png" class="popup_img_yes"/> <img src="no.png" class="popup_img_no"/> div> div> div> body>
- All the divs are separate containers where we refer them individually by the id and class names.
- Add this CSS inside the style tag.
<style> .popup{ position:fixed; width:100%; height:100%; left:0px; right:0px; top: 0px; bottom:0px; background-color:rgba(3,3,3,0.8); } .popupWindow{ background-color:white; margin:0px auto; width:40%; min-width:400px; min-height:300px; margin-top:12%; text-align: center; -moz-border-radius: 50px 50px / 50px 50px; border-radius: 50px 50px / 50px 50px; box-shadow: 10px 10px 5px #000; } .popup_txt{ font-size:26px; font-weight:bold; margin:10px; padding-top:100px; color:green; } .popup_img{ maring:10px; } .popup_img_yes,.popup_img_no{ margin:20px; } style>
- The CSS is applied to the div elements by referring to their id and class names. The id is referred by #idName and class is referred by .className
- Add these jquery scripts in your webpage inside head tag. All script must be written inside script tag.
<script> $(document).ready(function(){ $( ".popup_img_yes" ).click(function() { $( ".popup" ).fadeOut( 1200 ); }); $( ".popup_img_no" ).click(function() { window.open("https://www.google.com","_self"); }); }); </script>
- Know how it works. The jquery is used to handle the click event on the "yes" and "no" button and their corresponding action.
- If yes is clicked .fadeOut( 1200 ) method is called; here the popup will fade out in 1.2 seconds.
- If no is clicked the page is reloaded with the URL google.com using the function window.open. The attribute "_self" indicate that the url is loaded in the same tab.
Part 2 of 2:
Adding Buttons and Saving
- Find or create your own pictures for the yes and no, if desired.
- Enter the correct path for the picture src (source).
- Save your file with the extension .html to your local drive and run the saved file.
4 ★ | 1 Vote
You should read it
May be interested
- How to write on the web page with Simple Webpage Notesimple webpage note utility will create notes on the web and display notes right in the web interface.
- How to design a website in Photoshop (Part 2): Create a Landing page for travel websitesin this tutorial, we will use photoshop cs6 to design a simple, clean landing page for a travel website. in this process, you will be taught how to create custom grids with links, create fonts, use a lot of white space and compose web content in a professional way.
- Page numbering steps in Microsoft Word Microsoftpage numbering in microsoft word is a basic and very simple operation when you work with documents. for those who often have to print references, manuals, and textbooks, creating page numbers will help viewers find content faster, through the table of contents in word.
- How to create a page header (Header) and footer (Footer) in Wordcreating headers and footers is a way to help you mark ownership and help you present your science, quickly find content in the article. to create page titles and footers you go to the insert tab - header (create page titles) or
- How to turn off the chat frame automatically appears on the websiteutility hello, goodbye! will turn off all pop-up chat automatically displayed when accessing the website in the browser.
- Text file formatmany times you are struggling to know how to shoot a horizontal page in a whole page of text. or every time you create a new file you have to reformat the text for the page even though the previous and next margin sizes do not change, etc. tipsmake.com will guide you on how to format the page margins, rotate the horizontal page, vertical page
- How to turn to a new page and add a new page in Wordhow to turn to a new page and add a new page in word. for office workers, the word software is one of their most basic tools, with word users can create a lot of different content through the editing of typed text. word now owns many outstanding features that support the maximum for users.
- How to insert page numbers in Excelpage numbering in excel differs from page numbering in word, we will need to customize the page setup group in excel.
- How to delete a page in PDF - Delete 1 page of any document in a PDF fileediting a pdf file is not as simple as editing a word or excel file but it is not impossible. in this article, tipsmake.com will guide you on a simple way to delete pages in pdf files, please refer.
- How to add a new page in Wordto manually break the page, add a new page on word, we can use the keystroke quickly without having to do it manually.