Article Preview Component - Mobile-first Responsive CSS Javascript

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,
Please log in to post a comment
Log in with GitHubCommunity feedback
- @kenreibman
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
andbackground-color
from the.main
class.
I highly advise you against setting a fixed
height
and fixedwidth
for containers, backgrounds, etc. in your future projects, as this creates responsiveness issues down the line.I hope this helps!
Marked as helpful - I would also get rid of the
- @kenreibman
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