r/CodingHelp • u/Earendel999 • Sep 12 '26
[How to] Hello Coder! How to perfectly fit a 2752*1536 image in the Web-page ?
background-image: url("Wallpaper1.png");
background-position: center center;
background-size: cover;
background-repeat: no-repeat;
overflow-y: auto;
Hey! I am a beginner at this stuff and I am trying to make a website for a personal project but the image doesn't fit perfectly. Like bottom and sides part are cropped. I have noticed when I open the web page in different device everything is messed up in their position why is it ?
2
Upvotes
•
u/AutoModerator Sep 12 '26
Thank you for posting on r/CodingHelp!
Please check our Wiki for answers, guides, and FAQs: https://coding-help.vercel.app
Our Wiki is open source - if you would like to contribute, create a pull request via GitHub! https://github.com/DudeThatsErin/CodingHelp
We are accepting moderator applications: https://forms.fillout.com/t/ua41TU57DGus
We also have a Discord server: https://discord.gg/geQEUBm
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/Jasedesu Sep 12 '26
The behaviour you see is exactly what is expected from
background-size: cover;so you will need to change that if you want something different. Changingcovertocontainwill always show the whole image, but that comes at the cost of introducing space at the top/bottom or left/right edges. There are options that will stretch the image to fill all of the available space, but that will distort the image. At the end of the day, you will always need to compromise as you don't know for sure what size screen will be used to view your content.MDN: background-size CSS property
1
u/nuc540 Professional Coder Sep 15 '26
Just a gentle reminder that images’ aspect ratios and users browsers window’s ratio may not match, so there’s no magic way to make both the same; that’s just ratios/common sense.
So either the image needs to wrap the whole viewport thus you allow the image to be cropped, or you shrink the longer side of the image to be constrained within the ratio of the window which means showing empty space around the opposite side.
For a full screen bleed people tend to just use cover, as already mentioned. Good luck!