Как сделать изображение главного экрана на весь экран

Рейтинг: 0Ответов: 1Опубликовано: 02.03.2023

Я хочу чтобы фоновая картинка была до конца экрана на любом разрешении экрана Вот так

CSS

    background-color: #606060;
background-image: url(../img/main.jpg);
background-repeat: no-repeat;
background-size: cover;
background-blend-mode: multiply;
// background-position: 60%;
width: 100%; height:600px;
background-position: 100% 40%;

Чтобы воспроизвести проблемму у себя просто вставьте код себе в редактор кода

body {
    background-color: #202020;
    color:white;
}

.title h1,h2 {
    margin-top: 5%;
    display: inline-block;
    font-size: 18px;
    text-transform: uppercase;
}

img {
    margin-bottom: 1%;
    width: 5%;
}

main {
background-color: #606060;
    background-image: url(https://images.hdqwalls.com/download/8-bit-pixel-art-city-2o-1280x720.jpg);
    background-repeat: no-repeat;
    background-size: cover;
    background-blend-mode: multiply;
    // background-position: 60%;
    width: 100%; height:600px;
    background-position: 100% 40%;
} 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Temp</title>
    <link rel="stylesheet" href="css/bootstrap.css">
    <link rel="stylesheet" href="css/style.css">
</head>

<!-- 
    
For me
1920x1080 - https://wallpaperaccess.com/full/2942699.jpg
1280x720 - https://images.hdqwalls.com/download/8-bit-pixel-art-city-2o-1280x720.jpg

 -->

<body>

    <main>

        <div class="container">

            <div class="title">

                <div class="row">
                    <div class="col-lg-5 offset-lg-1">
                        <h1>Some text here</h1>
                        <img src="img/1_in_red_circle.svg" alt="">
                    </div>
                    <div class="col-lg-6">
                        <h2>Two sides of coin</h2>
                        <img src="img/2_in_red_circle.svg" alt="">
                    </div>
                </div>
            </div>
        </main> 
    </div>

</body>

</html>

Ответы

▲ 0

в body height: 100vh; и main немного изменил.

body {
    background-color: #202020;
    color:white;
    height: 100vh;
    margin: 0;
}

.title h1,h2 {
    margin-top: 5%;
    display: inline-block;
    font-size: 18px;
    text-transform: uppercase;
}

img {
    margin-bottom: 1%;
    width: 5%;
}

main {
background-color: #606060;
    background-image: url(https://images.hdqwalls.com/download/8-bit-pixel-art-city-2o-1280x720.jpg);
    background-repeat: no-repeat;
    width: 100%;
    height:100%;
    background-position: center;
    background-size: cover;
} 
<body>
  <main>
  <div class="container">
      <div class="title">
          <div class="row">
              <div class="col-lg-5 offset-lg-1">
                  <h1>Some text here</h1>
                  <img src="img/1_in_red_circle.svg" alt="">
              </div>
              <div class="col-lg-6">
                  <h2>Two sides of coin</h2>
                  <img src="img/2_in_red_circle.svg" alt="">
              </div>
          </div>
      </div>
    </div>
  </main>
</body>