Skip to content
  • Learning paths
  • Challenges
  • Solutions
  • Articles
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted about 3 years ago

Article Preview Component - Mobile-first Responsive CSS Javascript

bem
Rapha445•100
@Rapha445
A solution to the Article preview component challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


Hi everyone :)

This was quite a challenging one for me. I have a question about Javascript: I wanted to close the pop-up "share" section by clicking anywhere on the page, so I came up with the following Javascript:

html.addEventListener("click", function (e) {
shareLinks.classList.remove("active");
})

And I removed manually the parts of my html that are supposed to open the pop-up like so:

if (e.target !== shareBtn & e.target !== ImgHover & e.target !== shareLinks) 

But this can be a lengthy and laborious process. I was wondering if there is a better way to achieve this...

Any solution or any comments more than welcome! Cheers,

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

  • Ken•935
    @kenreibman
    Posted about 3 years ago

    I'd also like to mention that your desktop layout is broken and improperly styled.

    Your card is also off-center so I changed your css to have the card centered.

    body {
        min-height: 100vh;
        display: flex;
        flex-direction: column;
        justify-content: center;
        background-color: hsl(210, 46%, 95%);
    }
    
    • I would also get rid of the height and background-color from the .main class.

    I highly advise you against setting a fixed height and fixed width for containers, backgrounds, etc. in your future projects, as this creates responsiveness issues down the line.

    I hope this helps!

    Marked as helpful
  • Ken•935
    @kenreibman
    Posted about 3 years ago

    Sure! Your viewport width at 1440px currently looks like this

    About the fixed height and width, I mean you instead of using height with set px I recommend using min-height with rems and max-width for containers.

    Marked as helpful
  • Ken•935
    @kenreibman
    Posted about 3 years ago

    So, I actually spent the last hour trying to mess around with your code and figure out the solution to your question with vanilla JS.

    This little functionality is actually so common, and I've been trying to figure out an efficient way to do this with vanilla JS. I'm going to keep trying and let you know if I figure it out.

    Every resource on the internet recommends Bootstrap or jQuery, and I would recommend you use those frameworks in the future which makes those modals an easier task to create.

    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
Frontend Mentor logo

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

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

Oops! 😬

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

Log in with GitHub