Home > Mobile >  Why is my backgound image not showing up?
Why is my backgound image not showing up?

Time:10-26

I have put a image in the background but it is not appearing to me. I'm using bootstrap 5. How do I fix this ? I tried many things but none of them worked as I expected.

html {
  background: url(https://via.placeholder.com/150/0000FF/808080) no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <link rel="stylesheet" type="text/css" href="estilo.css">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <!-- displays site properly based on user's device -->
  <link rel="icon" type="image/png" sizes="32x32" href="./images/favicon-32x32.png">
  <title>Frontend Mentor | Base Apparel coming soon page</title>
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

</head>

<body>
  <div class="row">
    <div class="col-sm-6"><img src="https://via.placeholder.com/150/FF0000/808080" class="img-fluid"></div>
    <div class="col-sm-6">50%</div>
  </div>






  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg OMhuP IlRH9sENBO0LRn5q 8nbTov4 1p" crossorigin="anonymous"></script>
</body>

</html>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

You could use the <body> tag:

body { 
        background: url(https://via.placeholder.com/150/0000FF/808080) no-repeat center center fixed; 
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
      }

Otherwise the background image shows after your content.

See working example.

CodePudding user response:

Try to place your background image in the <body> tag, not in the <html> tag, so

body { 
       background: url(./images/bg-pattern-desktop.svg) no-repeat center center fixed;
       -webkit-background-size: cover;
       -moz-background-size: cover;
       -o-background-size: cover;
       background-size: cover;
     }
  • Related