0
Javascript
var inicio = document.getElementById('inicio-modal');
var banner = document.getElementById('banner-modal');
var produto = document.getElementById('produtos-modal');
function abreInicio(){
if (inicio.style.display == 'none') {
inicio.style.display = 'block';
banner.style.display = 'none';
produto.style.display = 'none';
}
}
function abreBanners(){
if (banner.style.display == 'none') {
banner.style.display = 'block';
inicio.style.display = 'none';
produto.style.display = 'none';
}
}
function abreProdutos(){
if (produto.style.display == 'none') {
produto.style.display = 'block';
inicio.style.display = 'none';
banner.style.display = 'none';
}
}
HTML
<div id="inicio-modal" class="modal"></div>
<div id="banner-modal" class="modal" style='display:none;'></div>
<div id="produtos-modal" class="modal" style='display:none;'></div>
CSS
.modal{
margin-left: auto;
margin-right: auto;
width: 100%;
max-width: 1024px;
}
When the page loads and the first modal is open, everything works perfectly, however, by clicking the buttons to open and close the modals, they lose their css margins.
In your code, when opening a modal, you assign it a
display: inline-block
. He’s like this by default?– Samir Braga
That was the mistake, thank you :D
– Murilo Melo
Murilo, don’t add "Fixed" to the title, you can (should :P) answer your own question and favorite it, so it will have the same purpose and will be better for new visits to understand how the problem was solved.
– Samir Braga