I have a modal working really well with one link using the code below, but what to do is get the code below to work with a much bigger number of links. So each button relates to displaying its own bit of text.
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
.modal-content {
background-color: #fefefe;
margin: 20% auto; /* 15% from the top and centered */
padding: 20px;
border: 1px solid #888;
width: 70%; /* Could be more or less, depending on screen size */
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
I know the id above would have to change, but wanted to keep it like this as wasnt sure how to change the script to accomodate it, and also obviously to keep the CSS as it is, and dont want to continually duplicate that either, and also that to open the nex one the one opened before needs to close first.
And the div above would have to be duplicated too to replicate the number of buttons, but again just wanted to keep it raw so i could see it done properly
Remember ids are unique so you can only have one a page and ids historically should not start with a digit (although I believe that is changing) but for backward compatibility I would avoid using numbers at the start of ids.
I also tweaked the CSS as vertical margins refer to the width of the element and not the height and thus make no sense in that context.
I think they get treated just as destinations only when the href is omitted.
What I should have done is supplied the destination in the href (href=“#a1”) rather than a data attribute and then grab the destination from the href with the js.
Ye you’d think so wouldnt you, but for some reason the close ‘X’ doesnt work on iphones or ipad. So changed it to a href’#’ and when it closes it refreshes and the user ends up at the top of the page
And I still couldnt get it working, so it must be something possibly in the code thats over riding what you have done, so then neededing me to overwrite it again.
Thinking about it, I may have another .close going on in another css file, will take a look.