user5447339 user5447339 - 1 year ago 127
CSS Question

How to create popups in css /Javascript?

I am trying to make popups containing list of lines:

  1. Support

  2. Contact

  3. Demo

In the 1st line, it should display Support. In the 2nd line, it should display Contact and in the 3rd line, it should display Demo.

I was able to create popups containing one line by following the w3schools link but I am not sure how to create popups having multiple lines.

The pictorial representation of what I am trying to get is shown here:
Popups with multiple lines

The code which I have used from the w3schools link is shown below:

<!DOCTYPE html> <html> <style> /* Popup container - can be anything you want */ .popup {
position: relative;
display: inline-block;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none; }

/* The actual popup */ .popup .popuptext {
visibility: hidden;
width: 160px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 8px 0;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -80px; }

/* Popup arrow */ .popup .popuptext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #555 transparent transparent transparent; }

/* Toggle this class - hide and show the popup */ .popup .show {
visibility: visible;
-webkit-animation: fadeIn 1s;
animation: fadeIn 1s; }

/* Add animation (fade in the popup) */ @-webkit-keyframes fadeIn {
from {opacity: 0;}
to {opacity: 1;} }

@keyframes fadeIn {
from {opacity: 0;}
to {opacity:1 ;} } </style> <body style="text-align:center">


<div class="popup" onclick="myFunction()">Click me to toggle the popup! <span class="popuptext" id="myPopup">Support</span> </div>

<script> // When the user clicks on div, open the popup function myFunction() {
var popup = document.getElementById('myPopup');
popup.classList.toggle('show'); } </script>

</body> </html>

In place of A Simple Popup, I have written Support. At this moment, I am able to get only one line as shown here: One line Popup

Answer Source

As a quick try do these steps to design what you want

1- open you mentioned link

2- change the html code to :

 <div class="popup" onclick="myFunction()">Click me to toggle the popup!
<div class="popuptext" id="div">
     <div><span id="myPopup">Support</span><br/></div>
     <div><span id="myPopup1">Contact</span><br/></div>
     <div><span id="myPopup2">Demo</span><br/></div>

3- change myFunction() code block to :

var popup = document.getElementById('div');

4- Add this css class to style element in head

 .popup .popuptext div{
   text-align: center;
   border-radius: 6px;  
   width: 160px; 

5- At the end run and see the result

but as you know there are several ways to design popup menu by front-end tools ,

but my solution is a quick design hope give you some help.

Additional helpful link

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download