Working on a little project that is an experimental foray into somewhat intermediate css. Learning via practical experience and all.
I'm currently designing a simple webpage that roughly looks like this on a screen:
The black space on the sides represent the empty space on the viewing screen, filled by solid color via background-color. The background is an image that's set to contain, so it scales with the screen without cropping, aligned to center. No scroll bars, always resizes to screen. What I want is for the other boxes within the background, to resize and scale proportionately with the background image, text and all, so that everything looks identical in terms of their positions relative to the background image, no matter how the browser window is resized. Like sort of grouping the layers together somehow, if that's possible? Because the button needs to be exactly right there, and the unnamed square thing, which is a translucent png that overlays itself on top of the background image.
Here's my code so far, or at least the relevant portion. This is just the background image and the button. The text and other images appear strange, so I'm sure I'm doing something entirely wrong there.
body {
background: url("images/Background.png") no-repeat fixed center;
background-size:contain;
background-color:black;
}
#enter_button {
background: rgba(26,0,0,0);
position:fixed;
transition: .5s ease;
top: 90%;
left: 50%;
transform: translate(-50%, -50%);
padding-top: 0.5vw;
padding-right: 1vw;
padding-bottom: 0.5vw;
padding-left: 1vw;
border: 0px;
border-radius: 10px;
max-width: 100%;
height:auto;
color: rgba(26,0,0,1);
font-size:5vw;
text-align:center;
}
#enter_button:hover {
transform: translate(-50%, -50%) scale(1.05);
background: rgba(26,0,0,0.2);
}
and here's the html body section.
<button id="enter_button">Enter</button>
The button scales properly if I resize the browser window along the aspect ratio of the background image, but disappears under the screen sometimes.
I was thinking perhaps div tags, but I can't quite figure out how.
I also heard that vw and vh aren't good units to scale to viewport, and to use this instead. Is that always better?
The problem is somewhat similar to this: Responsive DIV scaling within "background-size: contain" image But is there a pure css solution?