Article Preview Component - Mobile-first Responsive CSS Javascript
Design comparison
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,
Community feedback
- @kenreibmanPosted over 2 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
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 helpful1@Rapha445Posted over 2 years ago@kenreibman
Hello Ken, Thank you very much for your reply.
May I ask what appears broken and improperly styled on desktoo layout? I checked again but it looks good on my computer screen.
About the fixed height and width, do you mean that I should use responsive measurements like ems/rems or percentages instead? I wanted my container to stay at a specific size because of the absolute positioned element (the share bar). A responsive container would mess up the positioning...
0 - I would also get rid of the
- @kenreibmanPosted over 2 years ago
Sure! Your viewport width at
1440px
currently looks like thisAbout the fixed height and width, I mean you instead of using
height
with setpx
I recommend usingmin-height
withrems
andmax-width
for containers.Marked as helpful0@Rapha445Posted over 2 years ago@kenreibman Wow, for some reason it looks fine in Mozilla, but I'll try to find what happened in Chrome. Ok, got it! Thank you for all your advice!
0@kenreibmanPosted over 2 years ago@Rapha445 I tried on my tablet and it looks fine. it might just be my browser in my desktop. I’ll try to see if it works on my laptop too.
0 - @kenreibmanPosted over 2 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 helpful0@Rapha445Posted over 2 years ago@kenreibman
Thanks Ken, I have yet to learn Bootstrap and jQuery but I will soon look into it. I feel like it will probably make things easier.
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