Social proof section using React.JS and Tailwind CSS

Solution retrospective
This is my first challenge in tailwind css. I had to go through the documentation often to write code for this, at the end of the I feel happy for completing it.
What specific areas of your project would you like help with?I wanted to apply dynamic styles to the review and testimonial sections for larger screens using Tailwind CSS, but I was unable to do so. Instead, I created custom classes in index.css and applied them. Can someone review my approach and let me know if this is a good way of handling it?
Please log in to post a comment
Log in with GitHubCommunity feedback
- P@markuslewin
Hi!
Yes, Tailwind doesn't support dynamic class names. Instead, you can use an object to map the ID to a complete class name, or write custom selectors using "arbitrary variants":
// a) Map props to complete class names const marginById = { 1: "lg:ml-12", 2: "lg:ml-24", }; const Review = ({ item }) => { return <div className={`${marginById[item.id] ?? ""}`} />; }; // b) Custom selectors <div className="lg:[&:nth-child(2)]:ml-12 lg:[&:nth-child(3)]:ml-24" />;
Regarding the heading, the problem is that
hidden
hides the level-one heading for assistive technology as well. The class you're looking for issr-only
, so that the heading is only visually hidden, but still accessible to screen readers!Marked as helpful - @skyv26
Hi @nishanth1596,
Here’s some feedback and suggestions based on the points you provided. I hope these are helpful in refining your project! 🚀
1. Large Screen Design
- As mentioned earlier, ensure your designs are tested and optimized for larger screens. This ensures a consistent and polished user experience across all devices. 😊
2. Avoid Using
<section>
for Single Containers- Since the webpage is a single container, the
<section>
tag isn't necessary in this context. It might add unnecessary semantics and could confuse maintainers about the document structure. Consider simplifying it with a<div>
instead. 👍
3. Remove Comments from Production Code
- Keeping comments in production code can make it look unprofessional and cluttered. While they’re great for local testing and debugging, it’s good practice to remove them before committing or deploying.
- You can use tools like
eslint
orprettier
to enforce this. 🔧
4. Conditional Styling for Reviews or Cards
- Your idea of using breakpoints to style elements like cards or reviews is fantastic!
- For example, this snippet demonstrates a good practice:
Using utility classes dynamically based on screen size improves responsiveness and enhances the visual hierarchy. Keep it up! 🎨className="card rounded-lg bg-f7f2f7 lg:flex lg:max-w-[27.81rem] lg:items-center xl:bg-[#555555]"
Let me know if you need further assistance or clarification! 👨💻✨
Marked as helpful
Join 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