This is a solution to the FAQ accordion card challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.
Users should be able to:
- View the optimal layout for the component depending on their device's screen size
- See hover states for all interactive elements on the page
- Hide/Show the answer to a question when the question is clicked
- Semantic HTML5 markup
- CSS variables
- CSS with adjacent selectors
- Responsive layout
- Interaction with pure JavaScript
I learned to use adjacent selectors in CSS to add actions to the question container and the answer container, using just an "active" class.
And in javascript use only the "active" class to do all the accordion interactivity.
CSS Class e adjacent selector
.active{
font-weight: 700;
}
.active::after{
transform: rotate(180deg);
}
.container-question.active + .container-answer{
max-height: 8rem;
padding: 0 0 1rem 0;
border-bottom: .063rem solid var(--divires-color-light-grayish-blue);
}
- Frontend Mentor - @andrebdasilva
- Thank you all from the Frontend Mentor