Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted 3 months ago

Responsive article preview component using Tailwind CSS and JavaScript

tailwind-css
Amiko Elvis•260
@amikoelvis
A solution to the Article preview component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


What are you most proud of, and what would you do differently next time?

I’m most proud of implementing a responsive share menu that adapts seamlessly between mobile and desktop layouts, a core challenge of the Frontend Mentor project. Using JavaScript, I created a toggle system where the share button reveals social media links, replacing the author section on mobile and showing a popover with a triangle pointer on desktop. The isMobileView() function was key to handling these layout differences, and I’m thrilled with how the resize event listener ensures the UI resets correctly when switching screen sizes. Styling the menu with Tailwind CSS, especially the desktop triangle pointer using pseudo-elements ([&::after]), was a highlight, as it perfectly matched the design. Adding aria-label attributes to the share button and social links boosted accessibility, making the component more inclusive. Seeing the toggle work smoothly across devices while maintaining a clean, semantic HTML structure felt like a major win.

Next time, I’d add smooth animations to the share menu’s appearance, such as a fade or slide effect using Tailwind’s transition classes, to make the toggle more engaging. I’d also enhance accessibility by adding aria-expanded to the share button and managing focus for keyboard users, ensuring the first social link is focused when the menu opens. My JavaScript could be more modular—splitting the toggle logic into separate functions for opening and closing the menu would improve maintainability. I’d also refine the resize event listener to avoid unnecessary DOM updates by checking the menu’s current state. Finally, I’d test the component earlier on more devices and browsers to catch edge cases, like the share menu’s positioning on smaller desktop screens, and consider debouncing the resize handler for better performance.

What challenges did you encounter, and how did you overcome them?

Responsive Share Menu: Positioning the share menu (mobile: full-width bar, desktop: popover with triangle) was tough. I used Tailwind’s md: classes and isMobileView() in JavaScript, testing with DevTools to fine-tune md:right-[-215px] and pseudo-elements ([&::after]).

Share Menu Toggle: Toggling the menu (mobile: hide author, desktop: popover) caused layout glitches. I implemented device-specific logic with classList.toggle('hidden') and a mobile close button, debugging with console logs to ensure smooth transitions.

Tailwind CSS: Mastering Tailwind’s utilities (e.g., [&::after]:border-t-gray-700) was challenging. I followed Tailwind’s docs, building incrementally and checking in DevTools.

Triangle Pointer: Positioning the triangle (rotate-45) was tricky. I used trial-and-error with left-1/2 and translate-x-1/2, verifying alignment in DevTools.

What specific areas of your project would you like help with?

Animations for Share Menu: Issue: Abrupt toggle with hidden.

Help: Add fade/scale animation.

Solution:

html

<div id="share-menu" class="hidden opacity-0 scale-95 transition-all duration-300 ...">
js

shareBtn.addEventListener('click
Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • P
    devmd1997•280
    @devmd1997
    Posted 2 months ago

    Good use of tailwind to style your components. The javascript code is very clean and readable. I like how you utilized the same component for the share button toggle. Very good design!

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

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit all CSS, SCSS and Less files in your repository.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

How does the JavaScript validation report work?

When a solution is submitted, we use eslint to run an automated check on the JavaScript code.

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub