I have a css only, checkbox based accordion that works fine, except for some lengths of label text as the screen gets narrower, the arrow merges into the label text as shown in image below for "What is the weather like in Iquitos?"
Any idea how to keep this from happening? I have tried for a couple of hours, but have not found a fix.
/* Core styles/functionality */
.tab input {
position: absolute;
opacity: 0;
z-index: -1;
}
.tab__content {
max-height: 0;
overflow: hidden;
transition: all 0.35s;
margin-top: 0px;
}
.tab input:checked~.tab__content {
max-height: 30rem;
background-color: rgba(9, 221, 9, 0.12);
}
/* Visual styles */
.accordion-section {
width: 100%;
max-width: 1200px;
overflow: hidden;
}
.tab__label,
.tab__close {
display: flex;
color: #249e34;
cursor: pointer;
font-weight: 600;
font-size: clamp(1.13rem, 0.67vw + 0.92rem, 1.5rem);
}
.tab__label {
justify-content: space-between;
padding-right: 0.3125rem;
padding-top: 0.625rem;
padding-bottom: 0.625rem;
}
.tab__label::after {
content: "❯";
width: 1em;
height: 1em;
text-align: center;
transform: rotate(90deg);
transition: all 0.35s;
}
.tab input:checked+.tab__label::after {
transform: rotate(270deg);
}
.tab__content p {
margin: 0;
padding: 1rem;
}
.tab__close {
justify-content: flex-end;
padding: 0.5rem 1rem;
font-size: 0.75rem;
}
<section class="accordion-section">
<div class="tab">
<input type="checkbox" name="accordion-1" id="cb6">
<label for="cb6" class="tab__label">Can you support special diets?</label>
<div class="tab__content">
<p>Removed for space</p>
</div>
<div class="tab">
<input type="checkbox" name="accordion-1" id="cb7">
<label for="cb7" class="tab__label">What is the weather like in Iquitos?</label>
<div class="tab__content">
<p>Removed for space</p>
</div>
<div class="tab">
<input type="checkbox" name="accordion-1" id="cb8">
<label for="cb8" class="tab__label">Is laundry service available?</label>
<div class="tab__content">
<p>Removed for space</p>
</div>
</section>
2
Answers
Here is a simple example of how to apply flexbox:
Seems like you just need to give the
::after
element a bit more height so it can be accommodated. I would maybe add a flex gap to the container as well. Overall, I would recommend just using a standard HTML element over a pseudo element like this.