Я не могу заставить текст оставаться на заднем плане при изменении размера экрана - PullRequest
0 голосов
/ 21 октября 2018

Если я изменю размеры моего экрана, мой текст падает внизу фонового изображения.вот HTML и CSS с уважением.Я искал и пытался возиться с позицией абсолютной / относительной, как рекомендовано, но текст все равно отваливается.Любая помощь будет оценена.

<div id="stage">
<a><%= image_tag "5.jpg" %></a>
<a><%= image_tag "6.jpg" %></a>
<a><%= image_tag "7.png" %></a>
<a><%= image_tag "8.jpg" %></a>
<div id="banner-saying">"On a hike, the days pass with 
the wind, the sun, the stars; movement is powered by a 
belly full of food and water, not a noxious tankful of 
fossil fuels. On a hike, you're less a job title and more 
a human being. A periodic hike not only stretches the 
limbs but also reminds us: Wow, there's a big old world 
out there."
</div>
</div>


#stage {
  margin: 1em auto;
  width: 100%;
  height: 100vh;
  margin-bottom: 230px;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
}

#stage a {
  position: absolute;
  width: inherit; /* Added */
  height: inherit; /* Added */
}

#stage a img {
  position: relative;
  border: 1px solid #ccc;
  background: #fff;
  width: inherit; /* Added */
  height: inherit; /* Added */
}

#stage a:nth-of-type(1) {
  animation-name: fader;
  animation-delay: 3s;
  animation-duration: 1s;
  z-index: 20;
}

#stage a:nth-of-type(2) {
  z-index: 10;
}

#stage a:nth-of-type(n+3) {
  display: none;
}

@keyframes fader {
  from {
    opacity: 1.0;
  }
  to {
    opacity: 0.0;
  }
}

#banner-saying {
  z-index: 100;
  position: absolute;
  color: white;
  font-size: 14px;
  left: 10px;
  top: 770px;
  font-family: "Reenie Beanie", "Comic Sans MS", cursive, sans-serif;
;}

Спасибо, что прочитали, если у вас так далеко.:)

1 Ответ

0 голосов
/ 21 октября 2018

Да, так что не используйте реальное изображение в качестве фона.Лучший способ использовать изображение в качестве фона - использовать свойство background-image CSS.

W3Schools имеет довольно хорошую документацию для этого: https://www.w3schools.com/cssref/pr_background-image.asp

Основная идея заключается в том, что вы устанавливаетеbackground-image div, в котором находится текст. Но есть много других возможностей.

Я создал демо для вашего использования (JSFiddle: https://jsfiddle.net/sx6bqpju/2/):

<HTML>

  <body>
    <div id="stage">
      Cupcake ipsum dolor sit amet powder. Cookie fruitcake I love marzipan jujubes carrot cake sweet toffee. Cupcake jelly beans I love muffin macaroon chupa chups cupcake sweet oat cake. Chupa chups gingerbread powder jujubes chupa chups chocolate cake chocolate. Oat cake I love jelly gummies. I love chocolate cake sugar plum tootsie roll chocolate I love cake lollipop cotton candy. Sesame snaps donut I love lollipop liquorice I love chocolate croissant cotton candy. Chocolate chocolate bar dessert croissant I love. I love bonbon powder gingerbread halvah gummi bears bear claw. Pastry ice cream croissant cotton candy topping I love. Cake jelly beans jelly-o sesame snaps bear claw gummies pastry. Marzipan macaroon muffin biscuit pastry macaroon jujubes macaroon. I love gingerbread sweet candy canes cookie ice cream chocolate bar dessert I love. Macaroon oat cake dragée I love oat cake.

Sugar plum muffin I love topping cheesecake sesame snaps. Tart wafer croissant candy canes I love biscuit dragée fruitcake macaroon. Candy marzipan powder chocolate cake I love pudding powder. Marshmallow carrot cake brownie croissant toffee apple pie topping. Muffin tart cupcake danish candy fruitcake cheesecake. Jujubes marzipan croissant. Cookie cake jujubes cheesecake marzipan. Cupcake chocolate biscuit cheesecake pudding. Icing I love jelly-o pudding candy canes marshmallow toffee lemon drops danish. Candy canes chupa chups I love toffee. Icing croissant marzipan bonbon tootsie roll apple pie gummies ice cream. Tiramisu fruitcake biscuit. Sweet cotton candy cookie gummies bear claw.

Cookie candy canes toffee. Jelly topping fruitcake I love macaroon liquorice dragée ice cream. Chupa chups tootsie roll I love tart macaroon jelly-o danish. Cheesecake bonbon chocolate toffee marshmallow jujubes sesame snaps powder jujubes. I love I love cookie chocolate toffee jelly I love. Macaroon tiramisu macaroon chupa chups pastry. Cheesecake bear claw cotton candy sweet roll ice cream. Candy chupa chups I love ice cream I love halvah. Biscuit bonbon gummi bears liquorice I love. Ice cream I love liquorice chocolate cake lemon drops sweet caramels. Cake I love gummies cupcake. Icing oat cake jujubes.


    </div>

    <style>
      body {
        background: gray;
        margin: 0px;
        padding: 0px;
        min-height: 100%;
      }

      #stage {
        width: 100%;
        min-height: 100%;
        background-image: url('https://images.pexels.com/photos/724949/pexels-photo-724949.png');
        margin-bottom: 230px;
        display: flex;
        justify-content: center;
        flex-wrap: wrap;
        background-size: cover;
      }
    </style>
  </body>

</HTML>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...