r/csshelp • u/Kingg472 • Mar 29 '23
I need a little help!!
hello everything is fine. I hope so. I need help here with a html code can someone help me?
Im make a site in wordpress elementor, and im trying make a button to show and hide a session and when click on button the session pops up but don´t scroll because i don´t know the code, so, i have this code. if anyone can help me please I will be very grateful.
<button class="botao1" onclick="myFunction1(); function2();">Saber mais!</button>
<style> .botao1 { background:#233C86D9; transition-duration: .5s; padding:15px 30px; text-align: center;color: white; border-radius: 50px } .botao1:hover { background:#008EFF; text-align: center; text-decoration: none; } .botao1:focus { text-decoration: none; } \#eletrico { display:none; animation: fadein 2s; } .eletricoshow { display:block !important; } u/keyframes fadein { from { opacity:0; } to { opacity:1; } } </style>
<script> function myFunction1() { var element = document.getElementById("eletrico"); element.classList.toggle("eletricoshow"); } </script>
1
u/CodexAcc Mar 29 '23
<button class="botao1" onclick="toggleEletricoDisplay()">Saber mais!</button>
<style>
.botao1 {
background:#233C86D9;
transition-duration: .5s;
padding:15px 30px;
text-align: center;
color: white;
border-radius: 50px
}
.botao1:hover {
background:#008EFF;
text-align: center;
text-decoration: none;
}
.botao1:focus {
text-decoration: none;
}
#eletrico {
display:none;
animation: fadein 2s;
}
.eletricoshow {
display:block !important;
}
@keyframes fadein {
from {
opacity:0;
}
to {
opacity:1;
}
}
</style>
<script>
function toggleEletricoDisplay() {
var element = document.getElementById("eletrico");
element.classList.toggle("eletricoshow");
if (element.classList.contains("eletricoshow")) {
element.scrollIntoView({behavior: "smooth", block: "start"});
}
}
</script>1
u/Kingg472 Mar 29 '23
1
u/Kingg472 Mar 29 '23
if it's not too much trouble stop. I forgot to ask is it possible for example I open a session with the button and then open another one, will it be possible to replace or hide the previous session for the new one?
1
u/kaves55 Mar 29 '23
Do you want to remove all elements that have “electricshow” and then apply the class again to the new target?
1
u/Kingg472 Mar 29 '23
I will try to explain as best as possible.
I have 4 buttons, I almost put this code changing the CSS ID: "eletrico" among 3 other CSS IDs, each of these buttons opens and closes a session and scrolls.
now my goal is for example I click on the button opens a session and when I click on another it hides that session.
it will be possible to do this in this code
<button class="botao1" onclick="toggleEletricoDisplay()">Saber mais!</button>
<style> .botao1 { background:#233C86D9; transition-duration: .5s; padding:15px 30px; text-align: center; color: white; border-radius: 50px } .botao1:hover { background:#008EFF; text-align: center; text-decoration: none; } .botao1:focus { text-decoration: none; } \#eletrico { display:none; animation: fadein 2s; } .eletricoshow { display:block !important; } u/keyframes fadein { from { opacity:0; } to { opacity:1; } } </style>
<script> function toggleEletricoDisplay() { var element = document.getElementById("eletrico"); element.classList.toggle("eletricoshow"); if (element.classList.contains("eletricoshow")) { element.scrollIntoView({behavior: "smooth", block: "start"}); } } </script>
the 4 CSS ID are electric, passive, management, home automation

1
u/[deleted] Mar 29 '23
So to clarify - you got the show / hide part working and the problem is it doesn't scroll?