Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
100 views
in Technique[技术] by (71.8m points)

html - How do I get my background image to scroll?

See I have a working background and whenever I scroll down it scrolls with it. But when I scroll there is like a black box the color of the the background of the body at the bottom of the page. Any fixes? I will paste code below, thanks.

https://ibb.co/ZXcvtk1 - How it looks pre me scrolling.

https://ibb.co/fH1720B - How it looks post me scrolling, as you can see the image follows however it is covered by a box which I think is the background color for the html/body.

body, html {
height: 100%;
background-color: black;
z-index: -10;
}

span {
  position: absolute;
  top: 78%;
  left: 47%;
  transform: translate(-50%, -50%); 
  z-index: 10;
}

.bg {
    background-image: url(bg.png);
    height: 100%;
    background-position: fixed;
    background-repeat: no-repeat;
    background-size: cover;
    background-attachment: fixed;
    z-index: -5;
}

div.rectangle {
  position: fixed;
  bottom: 0;
  right: 20%;
  height: 100%;
  width: 60%;
  border: 3px solid blueviolet;
  background-color: white;
  z-index: 5;
}
<html>
<head>
  <title>Learn Yu-Gi-Oh! Normal Summon</title>
  <link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
   <div class="bg"></div>
   <div class="rectangle"></div>
   <span>
   <header>
   <h1>Normal Summon</h1>
   </header>
     <div id="Normal Summon Intro">
       <h2>What is a Normal Summon?</h2>
       <p>A Normal Summon is the most simple way to Summon a monster. The turn player can perform a Normal Summon during their Main Phase when the game has started.</p>
     </div>
     <div id="Normal Summon Mechanics">
       <h2>How it works?</h2>
      </div>
      <div id="Normal Summon">
        <h3>Normal Summon</h3>
        <p>To perform a Normal Summon, the player simply plays a monster directly from their hand into an available Main Monster Zone in face-up Attack Position, declaring that the monster is being Normal Summoned.</p>
        <p>After each Normal Summon, a Summon negation window opens, and either player may negate the summon. If not, the summon is considered successful, and the Summon Response Window opens, and each player, starting from the turn player, may response to the summon. If no action is taken, the game state becomes open again.</p>
        <p>Special Summon Monsters, including Ritual Monsters, cannot be Normal Summoned.</p>
      </div>
      <div id="Normal Set">
        <h3>Normal Set</h3>
        <p>Instead of Normal Summoning a monster in face-up Attack Position, a player may instead play that monster defensively by "Set", placing the monster in face-down Defense Position.</p>
        <p>The turn player can only Normal Summon or Set once per turn, and only once that turn. Monsters cannot be Normal Summoned in face-up Defense Position, unless stated otherwise.</p>
      </div>   
      <div id="Tribute Summon">
        <h3>Tribute Summon</h3>
        <p>In order to Normal Summon a Level 5 or higher monster from the hand, the player must Tribute monster(s) they control as a cost. This is called "Tribute Summon". Level 5 or 6 monster requires one Tribute, while Level 7 and higher monsters require two Tributes.</p>
        <p><strong>Tribute Set</strong> is the act of Setting Level 5 or higher monster from the hand. However, the monster is not revealed to the opponent.</p>
      </div>
      <div id="Gemini Monsters">
        <h3>Gemini monsters</h3>
        <p>Gemini monsters are a type of monster that are treated as Normal Monsters on the field, but they can be Normal Summoned again while already face-up on the field to make them Effect Monster and "unlock" their effect(s). (This Normal Summon counts as the player's one Normal Summon/Set per turn). If the monster in question is Level 5 or higher, no tribute is required, however.</p>
      </div>
      <div id="Multi Normal Summon">
        <h2>Multiple Normal Summon</h2>
      </div>
      <div id="Normal Summon Rule">
        <p>While a player may only perform 1 Normal Summon/Set per turn, there are three types of "Additional Normal Summon" effects which can increase this limit.</p>
      </div>
      <div id="Set New Normal Summon Limit">
        <h3>Set new Normal Summon/Set Limit</h3>
        <p>These effects simply set the Normal Summon/Set limit to a fixed number. They do not stack, and the one that grants the highest number will apply.</p>
      </div>
      <div id="Allow Mukti Normal Summon">
        <h3>Allows multiple Normal Summon</h3>
        <p>These effect gives the player additional Normal Summon/Set limit, but the player can only gain these effects once per turn. So, even the player applies multiple of these effects, they will get a total of 1 additional Normal Summon, the change is that the player has wider set of eligible monsters to be summoned this way.</p>
      </div>
      <div id="Perform Normal Summon">
        <h3>Performs a Normal Summon</h3>
        <p>These effects outright perform a Normal Summon, and the action does not count toward the turn's Normal Summon/Set limit. Player must outright perform the Normal Summon (or Set, if applicable) immediately after that effect resolves.</p>
      </div>
      </span>
  </body>
</html>
question from:https://stackoverflow.com/questions/65870708/how-do-i-get-my-background-image-to-scroll

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

welcome to stack overflow, you have set the background-attachment:fixed this means that the background will stay there and disappear while scrolling. Try to remove this property, here is the code:

body,
html {
    height: 100%;
    background-color: black;
    z-index: -10;
}

span {
    position: absolute;
    top: 78%;
    left: 47%;
    transform: translate(-50%, -50%);
    z-index: 10;
}

.bg {
    background-image: url(https://image.shutterstock.com/image-vector/happy-new-2021-year-hanging-600w-1850894878.jpg);
    height: 100%;
    background-position: fixed;
    background-repeat: no-repeat;
    background-size: cover;
    /* background-attachment: fixed; */
    z-index: -5;
}

div.rectangle {
    position: fixed;
    bottom: 0;
    right: 20%;
    height: 100%;
    width: 60%;
    border: 3px solid blueviolet;
    background-color: white;
    z-index: 5;
}
<html>
<head>
  <title>Learn Yu-Gi-Oh! Normal Summon</title>
  <link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
   <div class="bg"></div>
   <div class="rectangle"></div>
   <span>
   <header>
   <h1>Normal Summon</h1>
   </header>
     <div id="Normal Summon Intro">
       <h2>What is a Normal Summon?</h2>
       <p>A Normal Summon is the most simple way to Summon a monster. The turn player can perform a Normal Summon during their Main Phase when the game has started.</p>
     </div>
     <div id="Normal Summon Mechanics">
       <h2>How it works?</h2>
      </div>
      <div id="Normal Summon">
        <h3>Normal Summon</h3>
        <p>To perform a Normal Summon, the player simply plays a monster directly from their hand into an available Main Monster Zone in face-up Attack Position, declaring that the monster is being Normal Summoned.</p>
        <p>After each Normal Summon, a Summon negation window opens, and either player may negate the summon. If not, the summon is considered successful, and the Summon Response Window opens, and each player, starting from the turn player, may response to the summon. If no action is taken, the game state becomes open again.</p>
        <p>Special Summon Monsters, including Ritual Monsters, cannot be Normal Summoned.</p>
      </div>
      <div id="Normal Set">
        <h3>Normal Set</h3>
        <p>Instead of Normal Summoning a monster in face-up Attack Position, a player may instead play that monster defensively by "Set", placing the monster in face-down Defense Position.</p>
        <p>The turn player can only Normal Summon or Set once per turn, and only once that turn. Monsters cannot be Normal Summoned in face-up Defense Position, unless stated otherwise.</p>
      </div>   
      <div id="Tribute Summon">
        <h3>Tribute Summon</h3>
        <p>In order to Normal Summon a Level 5 or higher monster from the hand, the player must Tribute monster(s) they control as a cost. This is called "Tribute Summon". Level 5 or 6 monster requires one Tribute, while Level 7 and higher monsters require two Tributes.</p>
        <p><strong>Tribute Set</strong> is the act of Setting Level 5 or higher monster from the hand. However, the monster is not revealed to the opponent.</p>
      </div>
      <div id="Gemini Monsters">
        <h3>Gemini monsters</h3>
        <p>Gemini monsters are a type of monster that are treated as Normal Monsters on the field, but they can be Normal Summoned again while already face-up on the field to make them Effect Monster and "unlock" their effect(s). (This Normal Summon counts as the player's one Normal Summon/Set per turn). If the monster in question is Level 5 or higher, no tribute is required, however.</p>
      </div>
      <div id="Multi Normal Summon">
        <h2>Multiple Normal Summon</h2>
      </div>
      <div id="Normal Summon Rule">
        <p>While a player may only perform 1 Normal Summon/Set per turn, there are three types of "Additional Normal Summon" effects which can increase this limit.</p>
      </div>
      <div id="Set New Normal Summon Limit">
        <h3>Set new Normal Summon/Set Limit</h3>
        <p>These effects simply set the Normal Summon/Set limit to a fixed number. They do not stack, and the one that grants the highest number will apply.</p>
      </div>
      <div id="Allow Mukti Normal Summon">
        <h3>Allows multiple Normal Summon</h3>
        <p>These effect gives the player additional Normal Summon/Set limit, but the player can only gain these effects once per turn. So, even the player applies multiple of these effects, they will get a total of 1 additional Normal Summon, the change is that the player has wider set of eligible monsters to be summoned this way.</p>
      </div>
      <div id="Perform Normal Summon">
        <h3>Performs a Normal Summon</h3>
        <p>These effects outright perform a Normal Summon, and the action does not count toward the turn's Normal Summon/Set limit. Player must outright perform the Normal Summon (or Set, if applicable) immediately after that effect resolves.</p>
      </div>
      </span>
  </body>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...