VW is wider then my actual screen

Hi! I have a problem with setting width of my HTML elements. When I use 100vw as my width, it works out fine, but for some reason it is a little bit wider then my screen (I tried Chrome and Firefox, it's the same on both of these). BUT when I turn the responsive mode in dev tools, everything fixes itself no matter what is the width of viewport, everything works correctly. How can I fix that? I have <meta name="viewport" content="width=device-width, initial-scale=1"> in my HTML, so I have no idea what's wrong.
47 Replies
Mannix
Mannix•3y ago
did you reset the default margin/padding on the body? also did you set box-sizing to border-box?
Aleksandr M.
Aleksandr M.OP•3y ago
Yeah, did everything.
MarkBoots
MarkBoots•3y ago
code and screenshot or it didn't happen 😉 (codepen even better)
Aleksandr M.
Aleksandr M.OP•3y ago
Sure, there you go! https://codepen.io/dunder__alexander/pen/ZEorQRv this is basically all I have for my project from FrontEnd Mentor
MarkBoots
MarkBoots•3y ago
i can not see a y overflow
Aleksandr M.
Aleksandr M.OP•3y ago
Weird, I have it right here
MarkBoots
MarkBoots•3y ago
btw. when you use a background image to lay white (or very light) text on top. make sure you also use a background-color or gradient. When (for some reason) an image does not load. you can still read it are you zoomed in per chance?
Aleksandr M.
Aleksandr M.OP•3y ago
Got it, alright! No, I tried zooming in and out, still the same
MarkBoots
MarkBoots•3y ago
try
body::after{
content: "";
position: fixed;
width: 100vw;
height: 100vh;
top: 0;
background-color: purple;
z-index: 999;
}
body::after{
content: "";
position: fixed;
width: 100vw;
height: 100vh;
top: 0;
background-color: purple;
z-index: 999;
}
then you can see what element is sticking out
Aleksandr M.
Aleksandr M.OP•3y ago
Huh, now I only get overflowing purple screen
Aleksandr M.
Aleksandr M.OP•3y ago
Maybe it could a problem with my screen? Idk
MarkBoots
MarkBoots•3y ago
if you scroll to the right, can you see if there is content?
Aleksandr M.
Aleksandr M.OP•3y ago
Nope, only purple screen
MarkBoots
MarkBoots•3y ago
hm okay. so it is not overflowing issues. what happens if you make continaer-main div : 100% instead of 100vw.
Aleksandr M.
Aleksandr M.OP•3y ago
Same, huh
MarkBoots
MarkBoots•3y ago
happens in multiply browsers?
Aleksandr M.
Aleksandr M.OP•3y ago
Yup, Chrome and Firefox
Mannix
Mannix•3y ago
why do you declare width for the children when you already declared two columns in the parent of container-main? and you use 1fr
MarkBoots
MarkBoots•3y ago
can you make a clean empty document and test the width
body {
margin: 0;
width: 100vw;
height: 100vh;
background-color: red;
}
body {
margin: 0;
width: 100vw;
height: 100vh;
background-color: red;
}
Aleksandr M.
Aleksandr M.OP•3y ago
Because this happens if I remove width from grid elements:
Aleksandr M.
Aleksandr M.OP•3y ago
Doesn't happen in Codepen for some reason Is it because of the images?
MarkBoots
MarkBoots•3y ago
ohw, now i see the overflow. so that purple was not across the whole page
Aleksandr M.
Aleksandr M.OP•3y ago
No overflow this way Huh, I wonder what am I doing wrong
MarkBoots
MarkBoots•3y ago
here is your issue
MarkBoots
MarkBoots•3y ago
that part exceeds the 100vw width
Aleksandr M.
Aleksandr M.OP•3y ago
Alright, so the grid element is bigger than the screen. But how did that happen if I set it's width manually to 50vw each? I also set the width of the container to 100vw, and its width works fine
MarkBoots
MarkBoots•3y ago
well when it is 50vw, but the text doesnt fit anymore, it will let it grow
MarkBoots
MarkBoots•3y ago
Here audience can not break line, including the padding of the cell, it will push it out
MarkBoots
MarkBoots•3y ago
so make your media query kick in earlier. or take a better look at your grid setup
Aleksandr M.
Aleksandr M.OP•3y ago
Am I able to just clamp() the font size a little bit smaller? I have it already, but it seems like it's not small enough Sorry if I'm asking dumb questions, it's my first project
Mannix
Mannix•3y ago
but there should not be a gap in your local env if you remove the widths set for the children this is confusing me are you sure this all of css / html in the codepen?
Aleksandr M.
Aleksandr M.OP•3y ago
Yeah, definitely And it works like it should in codepen That gap was actually the reason I added width manually
Mannix
Mannix•3y ago
do the images themself have white border?
Aleksandr M.
Aleksandr M.OP•3y ago
They don't, but I'll try to set border to 0 just in case
Mannix
Mannix•3y ago
no i mean check the image not css
Aleksandr M.
Aleksandr M.OP•3y ago
No, images themselves are okay
Mannix
Mannix•3y ago
try setting the background-size to 200%
Aleksandr M.
Aleksandr M.OP•3y ago
Will do
Mannix
Mannix•3y ago
you can upload the images to imgur so we can use it in codepen
Aleksandr M.
Aleksandr M.OP•3y ago
Okay, just a moment
Aleksandr M.
Aleksandr M.OP•3y ago
Oh I think I fixed it I removed the width on both grid element and grid itself and everything stopped overflowing
Aleksandr M.
Aleksandr M.OP•3y ago
The problem was here all along Thanks everyone for helping me out, I really appreciate it!
Mannix
Mannix•3y ago
i asked about this exactly lol
Aleksandr M.
Aleksandr M.OP•3y ago
This is very helpful as well because I still have overflow when I shrink my screen too much, now I know why
Mannix
Mannix•3y ago
yeah big fonts on small screen is a no no
Aleksandr M.
Aleksandr M.OP•3y ago
Yeah, I thought I removed everything but I didn't Do you think it's better to clamp it smaller or there is another way?
Mannix
Mannix•3y ago
I would clamp it yeah
Want results from more Discord servers?
Add your server