I have a div (page2box) which is centered on the screen, which in turn in divided intro different divs. They look like this:
What I want is, when I click on the Capture the Flag div, all other divs (Hackathon, Competitive prog… and Artificial Intelligence) disappear and then the Capture the Flag div covers the entire div(page2box).
Here’s the relevant code:
#page2{
background: linear-gradient(-180deg, #2B1F2D, rgb(77, 35, 49), rgb(87, 23, 44));
height:100vh;
}
#page2box{
height:90vh;
width: 90%;
background-color: darkblue;
position: relative;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
}
.page2Items{
height:100%;
width:25%;
}
.upper{
height:40%;
width:100%;
font-family: 'Cinzel', Arial, Helvetica, sans-serif;
font-size: 280%;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
.lower{
height:60%;
font-family: 'Average', sans-serif;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
font-size: 150%;
text-align: center;
}
#elem1{
background-color: cyan;
}
#elem2{
background-color: red;
}
#elem3{
background-color: blueviolet;
}
#elem4{
background-color: orangered;
}
<div id = "page2">
<div id="page2box">
<div class="page2Items" id="elem1">
<div class="upper">Capture The Flag</div>
<div class="lower">Lorem ipsum dolor sit amet, consectetit. Mosielit. Mosim felis libero, tincidunt eu odio vel, vulputate tinci Integer odio dolor, elementum in sem a, tristique cursus tortor. Duis sodales varius turpis ac aliquam. Integer congue fermentum posuere. Pellentesque varius massa at justo laoreet, non interdum nunc pretium. Integer porttitor tempor ante, vel laoreet sem placerat in.</div>
</div>
<div class="page2Items" id="elem2">
<div class="upper">Hackathon</div>
<div class="lower">Lorem ipsum dolor sit amet, consectetit. Mosielit. Mosim felis libero, tincidunt eu odio vel, vulputate tinci Integer odio dolor, elementum in sem a, tristique cursus tortor. Duis sodales varius turpis ac aliquam. Integer congue fermentum posuere. Pellentesque varius massa at justo laoreet, non interdum nunc pretium. Integer porttitor tempor ante, vel laoreet sem placerat in.</div>
</div>
<div class="page2Items" id="elem3">
<div class="upper">Competitive Prog...</div>
<div class="lower">Lorem ipsum dolor sit amet, consectetit. Mosielit. Mosim felis libero, tincidunt eu odio vel, vulputate tinci Integer odio dolor, elementum in sem a, tristique cursus tortor. Duis sodales varius turpis ac aliquam. Integer congue fermentum posuere. Pellentesque varius massa at justo laoreet, non interdum nunc pretium. Integer porttitor tempor ante, vel laoreet sem placerat in.</div>
</div>
<div class="page2Items" id="elem4">
<div class="upper">Artificial Intelligence</div>
<div class="lower">Lorem ipsum dolor sit amet, consectetit. Mosielit. Mosim felis libero, tincidunt eu odio vel, vulputate tinci Integer odio dolor, elementum in sem a, tristique cursus tortor. Duis sodales varius turpis ac aliquam. Integer congue fermentum posuere. Pellentesque varius massa at justo laoreet, non interdum nunc pretium. Integer porttitor tempor ante, vel laoreet sem placerat in.</div>
</div>
</div>
</div>
I tried to change the innerHTML of the page but that created a lot of mess. How do I make this happen? If possible, please try to present a solution which uses plain CSS and/or vanilla JS only.
3
Answers
In Above Add onclick Function to your div
And Add Following Javascript code in Javascript Code should be working fine
The below changes will do the job:
In HTML add click event passing the id on each div (which the user is clicking):
There is no change required in css file. The JS will handle the functionality.
Hope this works as expected.
**You can control that using javascript **
Following can be steps
Psudo code can be