I’m not sure if this is the best approach, but it works. Also, remember that the following code only works with a single resolution. Therefore, the image can be pixelated.
.fundo-login {
background-attachment: fixed; /* Faz com que a imagem fique fixa */
background-image: url('https://picsum.photos/354/300');
background-size: cover; /* Faz com que a imagem se estenda proporcionalmente */
background-position: center center; /* A propriedade anterior pode recortar a image. Por isso, usaremos o background-position para centralizar o corte e tentar capturar o foco da imagem. */
}
<body class="fundo-login">
<div>
Alguma besteira aqui dentro.
</div>
</body>
If you want to solve the mentioned problem (pixelated image), alternatively, you can use this other approach. Thus, you will be able to serve an image with different resolution for each viewport.
.fundo-login {
background-attachment: fixed; /* fixa imagem */
background-image: url('https://picsum.photos/354/300');
background-size: cover;
background-position: center center;
}
@media (min-width: 530px) { /* Baixa imagem igual a anterior, mas com resolução de 530x420*/
.fundo-login {
background-image: url('https://picsum.photos/530/420');
}
}
@media (min-width: 720px) { /* Baixa imagem igual a anterior, mas com resolução de 720x530*/
.fundo-login {
background-image: url('https://picsum.photos/720/530');
}
}
@media (min-width: 1024px) { /* Baixa imagem igual a anterior, mas com resolução de 1024x780*/
.fundo-login {
background-image: url('https://picsum.photos/1024/780');
}
}
<body class="fundo-login">
<div>
Alguma besteira aqui dentro.
</div>
</body>
Note: To use the previous method, you must render the different resolutions in some appropriate program and then put them on the server. So, in other words, the browser won’t convert automatically, but download according to resolutions.
Note: the resolutions used are not standards. So feel free to choose your.
It’s not very clear. The background image is not getting fixed?
– Sam
From what I understand the problem is that the image is very small, put your html and css code relevant
– Costamilam
try increasing . fundologin [ height:100%]
– Arsom Nolasco