0
I’m on a little something. I need your help for a change.
I’m practicing on a personal project, the effect Light Box and if possible would like to hear the dear(a)s colleague. Whether pointing out errors or changes for didactic purposes, constructive criticism will always be welcome!
Code
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
border: 1px solid #e7e7e7;
background-color: #f3f3f3;
}
li {
float: left;
}
li a {
display: block;
color: #666;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover:not(.ativo) {
background-color: #ddd;
}
li a.ativo {
color: white;
background-color: #4CAF50;
}
.escurecer{
display: none;
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
background: black;
z-index:1001;
opacity:.80;
}
#sobre {
display: none;
position: absolute;
top: 30%;
left: 37%;
width: 25%;
height: 37%;
padding: 16px;
border: 3px solid gray;
background-color: white;
z-index:1002;
overflow: auto;
text-align: center;
}
#contato {
display: none;
position: absolute;
top: 30%;
left: 37%;
width: 25%;
height: 37%;
padding: 16px;
border: 3px solid gray;
background-color: white;
z-index:1002;
overflow: auto;
text-align: center;
}
<ul class="topnav">
<li><a class="ativo" href="#inicio">Inicio</a></li>
<li><a href="#contato" onclick="document.getElementById('contato').style.display='block';document.getElementById('escurecer').style.display='block'">Contato</a></li>
<li><a href="#sobre" onclick="document.getElementById('sobre').style.display='block';document.getElementById('escurecer').style.display='block'">Sobre</a></li>
</ul>
<div id="sobre" class="box"><h4>Sobre nós</h4><hr><br>
<p>Lorem ipsum...</p>
</div>
<div id="contato" class="box"><h4>Fale conosco</h4><hr><br>
<p>Lorem ipsum...</p>
</div>
<div id="escurecer" class="escurecer" onclick="document.getElementById('escurecer').style.display='none';document.getElementById('sobre').style.display='none';document.getElementById('contato').style.display='none';"></div>
Problem - I think it could improve the functional mode of the stretch:
<div id="escurecer" class="escurecer" onclick="document.getElementById('escurecer').style.display='none';document.getElementById('sobre').style.display='none';document.getElementById('contato').style.display='none';"></div>
document.getElementById('sobre').style.display='none';
document.getElementById('contato').style.display='none';"
This is for cleaning/hiding divs
floating.
I was wondering if someone would propose something to me.. Let’s say more beautiful about this repetition of lines.
Reminder - All the source code presented here, works round. I only came to reap improvements or alternatives in the given section. In which I find this very amateur.
I made an edit to close the modal by clicking on
div
darken– Rafael Augusto
I understand what you meant by - "There are several ways to do this, a basic example to make your code cleaner is... evaluate an arithmetic expression using the function.
let
". Well, I interpreted your code that way. It was cool!– Diego Henrique
I came across an obstacle, which comes down to the code of the script. I mean, I could not use it among the tags
<head></head>
. But yes, among the tags</body>
and</html>
. Thus the HTML document, saves time for theload
of the elements themselves, be complete. And the console do not accuse hownull
(This means that the predestined elements do not yet exist). It also serves for the "script" being in external file, thus -</body><script src="script/script.js"></script></html>
. I leave it at that, so that everyone knows how to solve it. Without further ado, I thank you.– Diego Henrique
@Diegohenrique the nominee is between the tags
<body></body>
same, and if possible in a fileexterno
.– Rafael Augusto
@Diegohenrique I erred rs sorry, the correct is to use at the end before the closure of
<body>
all theJS
must be at the end of it.– Rafael Augusto