Design comparison
Solution retrospective
I would like to sort an issue in this project I worked on. The border-bottom below "Ingredients and Instructions" sections are taking the full screen width in tab and mobile screens unlike the desktop screen were the border-bottom below those sections are perfectly centralized only occupying the width of the contents and not the entire screen width. I have tried all I could to fix this problem on mobile and tab screens but I can't pin-point where the problem is coming from. Thanks in advance!
Community feedback
- @JedyokeyPosted 9 months ago
Thank you! I appreciate the response in taking time to review the code. So for the .flex-container class, I edited the padding
.flex-container { width: 100%; padding-left: 15px; padding-right: 15px; border-radius: 0; }``` as well as the image div .img-bg { margin: -30px -30px 0 -30px; }``` The issue is not solved perfectly but this is the closest thing I can get
0 - @CarlHummPosted 9 months ago
Hi Jedy.
Mobile/Tablet CSS
@media screen and (max-width: 992px) .flex-container { width: 100%;
Desktop CSS
.flex-container { width: 50%; margin: auto; }
Your CSS Explained
The media query sets the flex-container to 100% width on any resolution less than 992px. So, tablets/mobiles. Because this container contains all your sections, and your sections do not have a width set, they will take up 100% of space available in
.flex-container
and span the full page width.For devices above 992px in resolution, like desktops, they will instead have this container set to 50% and a margin: auto applied to center it. As you can guess, this would also limit the parents children (sections) to a max width of 50% of the viewport width, and center them.
By limiting the width of these sections to 50%, and centering them, their borders also only take up this amount of space. The sections are not "occupying the width of their contents" but instead occupying the width of their parent, which is
.flex-container
, which is 50%.What should you do?
If you don't want the border/sections to take up full width on mobile you could:
- Set a different width for
flex-container
- Add margin/padding to body element
- Set max-widths for nested sections
Hope this helps, feel free to ask any questions.
0 - Set a different width for
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