Hi I’m doing up a company site and ran into some issues with the code. Basically the accordion panel when zoomed in or out will increase or decrease, so it will “overflow” or be shorter than the accordion bar. Ideally it is supposed to “flow” with the accordion no matter at what resolution or zoom setting (or browser for that matter).
I’m not really proficient with coding (really beginner level), this code was written by a friend. I’m just wondering is there a better way to do it as such. Writing more @media conditions seemed to be ignored or nothing happens. Suspect the issue is under .Panel section. Posting here as I think the community of mentors seems quite approachable and capable.
Side note: This website is built on StandOut platform, where coding is a bit rigid. If we want any customisation, we have to hard code around the pre-built settings.
This is the code below:
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
}
@media screen and (min-width: 300px) and (max-width: 700px) {
.hp{
display: block;
float: center;
margin-left: auto;
margin-right: auto;
margin-bottom: 10px;
width: 140px;
height:80px;
box-sizing: border-box;
}
/* Create two equal columns that floats next to each other */
.columnp {
float: left;
width: 50%;
}
/* Clear floats after the columns */
.rowp:after {
content: "";
display: table;
clear: both;
}
.accordion {
background-color: #8494cb;
color: white;
cursor: pointer;
width: 84%;
border: none;
text-align: left;
outline: none;
padding: 3px;
float: left;
vertical-align: top;
font-size: 7px;
font-family: sans-serif;
transition: 0.4s;
}
.active, .accordion:hover {
background-color: #8c94cc;
color: white;
}
.panel {
padding: 0 3px;
width:80.8%;
display: none;
background-color: #6d7dbd;
overflow: hidden;
color: inherit;
font-family: sans-serif;
font-size:7px;
opacity: 0.6;
border: none;
float: left;
text-align: left;
margin-left: auto;
margin-right: auto;
}
.accordion:after {
content: '\002B';
font-size: 7px;
color: #white;
font-weight: bold;
float: right;
}
.active:after {
content: "\2212";
}
}
@media screen and (min-width: 700px) and (max-width: 1146px) {
.hp{
display: block;
float: center;
margin-left: auto;
margin-right: auto;
margin-bottom: 15px;
width: 320px;
height:240px;
box-sizing: border-box;
}
/* Create two equal columns that floats next to each other */
.columnp {
float: left;
width: 50%;
}
/* Clear floats after the columns */
.rowp:after {
content: "";
display: table;
clear: both;
}
.accordion {
background-color: #8494cb;
color: white;
cursor: pointer;
width: 86%;
border: none;
text-align: left;
outline: none;
padding: 5px;
float: left;
vertical-align: top;
font-size:12px;
font-family: sans-serif;
transition: 0.4s;
}
.active, .accordion:hover {
background-color: #8c94cc;
color: white;
}
.panel {
padding: 0 10px;
width:80.9%;
display: none;
background-color: #6d7dbd;
overflow: hidden;
color: inherit;
font-family: sans-serif;
font-size:12px;
opacity: 0.6;
border: none;
float: left;
text-align: left;
margin-left: auto;
margin-right: auto;
}
.accordion:after {
content: '\002B';
font-size: 12px;
color: #white;
font-weight: bold;
float: right;
}
.active:after {
content: "\2212";
}
}
@media screen and (min-width: 1299px) {
.hp{
float:center;
margin-left: 34%;
margin-right: 34%;
display: block;
box-sizing: border-box;
}
/* Create two equal columns that floats next to each other */
.columnp {
float: left;
width: 50%;
}
/* Clear floats after the columns */
.rowp:after {
content: "";
display: table;
clear: both;
padding-bottom: 8.5em;
}
.accordion {
background-color: #8494cb;
color: white;
cursor: pointer;
padding: 18px;
width: 68%;
border: none;
text-align: left;
outline: none;
float: left;
font-size: 15px;
font-family: sans-serif;
transition: 0.4s;
}
.active, .accordion:hover {
background-color: #8c94cc;
color: white;
}
.panel {
padding: 0 20px;
width:63.4%;
display: none;
background-color: #6d7dbd;
overflow: hidden;
color: inherit;
font-family: sans-serif;
font-size:15px;
opacity: 0.6;
border: none;
float: left;
text-align: left;
margin-left: auto;
margin-right: auto;
}
.accordion:after {
content: '\002B';
font-size: 13px;
color: #white;
font-weight: bold;
float: right;
margin-left: 5px;
}
.active:after {
content: "\2212";
}
}
</style>
</head>
<body>
<div class="rowp">
<div class="columnp" >
<img src="https://raw.githubusercontent.com/adminHeng/WBSH/main/ux-gun-5Mj4PO7KIFc-unsplash.jpg" alt="Smiley face image" class = "hp" width="480"
height="380">
</div>
<div class="columnp" >
<button class="accordion">MILITARY</button>
<div class="panel">
<ul>
<li>TENGAH AIRBASE</li>
<li>CHANGI AIRBASE</li>
<li>RIFLE RANGE CAMP</li>
</ul>
</div>
</div>
</div>
<div class="rowp">
<div class="columnp" >
<img src="https://raw.githubusercontent.com/adminHeng/WBSH/main/yamin-ohmar-l8TYuY4wlyQ-unsplash.jpg" alt="Smiley face image" class = "hp" width="480"
height="380">
</div>
<div class="columnp" >
<button class="accordion">PRIVATE RESIDENTIAL</button>
<div class="panel">
<ul>
<li>TENET EXECUTIVE CONDOMINIUM</li>
<li>AMBER PARK</li>
</ul>
</div>
</div>
</div>
<div class="rowp">
<div class="columnp" >
<img src="https://raw.githubusercontent.com/adminHeng/WBSH/main/peerapon-chantharainthron-kavu6S_qtYo-unsplash.jpg" alt="Smiley face image" class = "hp" width="480"
height="380">
</div>
<div class="columnp" >
<button class="accordion">TRANSPORT/INFRASTRUCTURE</button>
<div class="panel">
<ul>
<li>JURONG EAST LTA HUB J120</li>
</ul>
</div>
</div>
</div>
<div class="rowp">
<div class="columnp" >
<img src="https://raw.githubusercontent.com/adminHeng/WBSH/main/mk-s-WHf1wtNMMLU-unsplash.jpg" alt="Smiley face image" class = "hp" width="480"
height="380">
</div>
<div class="columnp" >
<button class="accordion">RECREATIONAL</button>
<div class="panel">
<ul>
<li>BOTANIC GARDEN</li>
<li>MANDAI BIRD PARADISE</li>
<li>CHENGKAT COMMUNITY CENTRE</li>
<li>PALAWAN BEACH SENTOSA</li>
<li>SEMBAWANG SPORTS HUB</li>
</ul>
</div>
</div>
</div>
<div class="rowp">
<div class="columnp" >
<img src="https://raw.githubusercontent.com/adminHeng/WBSH/main/american-public-power-association-RQpeu8lbti4-unsplash.jpg" alt="Smiley face image" class = "hp" width="480"
height="380">
</div>
<div class="columnp" >
<button class="accordion">SUBSTATION</button>
<div class="panel">
<ul>
<li>LABRADOR SUBSTATION</li>
<li>JURONG NEA SUBSTATION</li>
<li>TENGAH SUBSTATION</li>
</ul>
</div>
</div>
</div>
<script>
var acc = document.getElementsByClassName("accordion");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function() {
this.classList.toggle("active");
var panel = this.nextElementSibling;
if (panel.style.display === "block") {
panel.style.display = "none";
} else {
panel.style.display = "block";
}
});
}
</script>
</body>
</html>
Hope someone can assist with this! Much appreciated. Thanks.
Lemuel