Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Article Preview Component - Mobile-first Responsive CSS Javascript

#bem
Rapha445• 100

@Rapha445

Desktop design screenshot for the Article preview component coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
1newbie
View challenge

Design comparison


SolutionDesign

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

Ken• 935

@kenreibman

Posted

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

1

Rapha445• 100

@Rapha445

Posted

@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
Ken• 935

@kenreibman

Posted

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

0

Rapha445• 100

@Rapha445

Posted

@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
Ken• 935

@kenreibman

Posted

@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
Ken• 935

@kenreibman

Posted

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

0

Rapha445• 100

@Rapha445

Posted

@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 GitHub
Discord logo

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