I'm trying to create responsive accordion using the below code:
<div class="tabs specs">
<div class="tab">
<input type="checkbox" id="chck1">
<label class="tab-label" for="chck1">GIFT DETAILS</label>
<div class="tab-content">
<p>Simple and Elegant Love Letter/Card Message Included Inside Standard Gift Box.</p>
</div>
</div>
<div class="tab">
<input type="checkbox" id="chck2">
<label class="tab-label" for="chck2">SHIPPING TIME</label>
<div class="tab-content">
<p>Simple and Elegant Love Letter/Card Message Included Inside Standard Gift Box.</p>
</div>
</div>
</div>
<style>
.tabs {
overflow: hidden;
}
.tab {
width: 100%;
color: white;
overflow: hidden;
}
.tab-label {
display: -webkit-box;
display: flex;
-webkit-box-pack: justify;
justify-content: space-between;
padding-top: 0.5em;
padding-bottom: 0.5em;
background: white;
font-weight: bold;
font-size: 15px;
cursor: pointer;
color: #333333;
/* Icon */
}
.tab-label:hover {
background: white;
}
.tab-label::after {
content: "\276F";
width: 1em;
height: 1em;
text-align: center;
-webkit-transition: all .35s;
transition: all .35s;
}
.tab-content {
max-height: 0;
padding: 0 1em;
color: #333333;
background: white;
-webkit-transition: all .35s;
transition: all .35s;
}
input:checked + .tab-label {
background: white;
}
input:checked + .tab-label::after {
-webkit-transform: rotate(90deg);
transform: rotate(90deg);
}
input:checked ~ .tab-content {
max-height: 100vh;
padding: 1em;
}
.specs input {
position: absolute;
opacity: 0;
z-index: -1;
}
</style>
While the accordion is working on Safari (both mobile and desktop) there was an error where the content was revealed even before I clicked on the tab itself.
I have tried to use max-height: auto but it didn't work. Could someone let me know what I was doing wrong?