Responsive FAQs accordion with the help of display flex, position.
Design comparison
Solution retrospective
Hi, I got to know the idea to use for Each in real projects. This project taught me a lot. The technologies I used were HTML, CSS, and JavaScript.
I gave my best to this project. Please help me to improve my code.
Thanks
Community feedback
- @grace-snowPosted 10 months ago
I hope this is helpful
- Use the picture element for serving responsive images not hiding/showing different ones with css. The picture element is far more performant, only downloading the relevant image for the users screen size, not both of them like with the css method.
- Decorative images must have empty alt. There's a good post in the resources channel on discord about how and when to write alt text.
- The section element is not appropriate here. All of this content should be within a
main
landmark. - This is currently completely inaccessible because of your html (and js). It needs more than just buttons. Read my tutorial. It is essential to consider your html carefully.
- It's better for performance to link fonts in the html head instead of css imports.
- Always use a modern css reset at the start of the styles in every project. Look up Andy Bell's one and get into the habit of using a full one.
- Don't style on IDs. That's not what they are for and it increases css specificity drastically (never a good thing)
- The component max width should be in rem not px.
- Use flex or grid properties to center a component in the viewport not position absolute. Personally I wouod use css grid for this whole page layout.
- Do not use floats! You will almost never need them in modern development. The only time may be in prose content like a blog if you want text to flow around images.
- Mobile styles should be the default.
- Do not write media queries like this. They must be defined in rem or em not px. And if working desktop first you will only need max-width not a max and min width in combination. When working mobile first you will only need a min width media query. See fedmentor.dev/posts/responsive-meaning
Marked as helpful0@Priyanshu-WDPosted 10 months agoHey, @grace-snow, thank you so much, I get to know a lot. As a self-taught developer, it's really helpful for me.
0 - @petritnurediniPosted 10 months ago
Congratulations on completing your FAQ Accordion project! 🌟 Your project shows a great understanding of HTML, CSS, and JavaScript, creating a functional and visually appealing FAQ section. Here are some suggestions to further improve your project:
-
HTML Best Practices:
- Semantic HTML: Use semantic HTML tags where possible. For example, consider using
<button>
instead of<div>
for interactive elements. - Alt Text: Good job using alt text for images! Ensure it's descriptive for better accessibility.
- Semantic HTML: Use semantic HTML tags where possible. For example, consider using
-
CSS Styling:
- Consistent Naming Convention: Use a consistent naming convention for your CSS classes to improve readability and maintainability.
- Responsive Design: Test your design on various screen sizes. Consider using relative units like
em
orrem
instead ofpx
for better scalability.
-
JavaScript Enhancements:
- Code Refactoring: The JavaScript code can be refactored to make it more concise. For example, you can toggle a class to show/hide the accordion content instead of directly manipulating styles.
- Event Delegation: Use event delegation to handle click events on dynamically added elements or to reduce the number of event listeners.
-
Performance and Accessibility:
- Lazy Loading Images: Implement lazy loading for images that are not immediately visible to improve page load times.
- Keyboard Accessibility: Ensure that the accordion can be operated using keyboard controls for better accessibility.
-
Code Organization:
- Separate Concerns: Separate CSS, JavaScript, and HTML into distinct files if not already done. This makes the codebase cleaner and easier to manage.
-
Further Learning:
- CSS Animations: Explore CSS animations to enhance the user experience. For example, smooth transitions for accordion opening/closing.
- Accessibility Features: Learn more about ARIA roles and properties to make your accordion more accessible.
- Learning Resources: MDN Web Docs for detailed documentation on HTML, CSS, and JavaScript.
You've made an impressive effort in creating this FAQ Accordion. Keep up the great work and continue to challenge yourself with new and more complex projects. Your progress is excellent, and I'm excited to see what you'll create next! Keep coding and exploring! 🚀
Marked as helpful0@Priyanshu-WDPosted 10 months agoHey, @petritnuredini, thank you as your comment gave me an area to work.
0 -
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord