background-attachment:固定>短时间后调整图像大小

时间:2018-12-13 16:40:26

标签: css bootstrap-4 resize parallax background-attachment

对不起,这个愚蠢的问题已经问了很多,但是我阅读并测试过的所有解决方案都不适合我...

我正在尝试使用轮播背景创建这种视差效果:https://www.w3schools.com/howto/tryhow_css_parallax_demo.htm 这是给我父亲的网站的,我想为他准备本周的礼物(HB爸爸!)

这是我的代码:

html {
  font-family: sans-serif;
  line-height: 1.15;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  -ms-overflow-style: scrollbar;
  -webkit-tap-highlight-color: transparent;
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.5;
  color: #212529;
  text-align: left;
  background-color: #fff;
  height: 100%;
}

.carousel-item {
  height: 75vh;
  min-height: 500px;
  background: no-repeat center center scroll;
  background-attachment: fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
 }
<!DOCTYPE html>
<html lang="en">

  <head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Half Slider - Start Bootstrap Template</title>

    <!-- Bootstrap core CSS -->
    <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="css/half-slider.css" rel="stylesheet">

  </head>

  <body>

    

    <header>
      <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
        <ol class="carousel-indicators">
          <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
          <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
          <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
        </ol>
        <div class="carousel-inner" role="listbox">
          <!-- Slide One - Set the background image for this slide in the line below -->
          <div class="carousel-item active" style="background-image: url('img/slide1.jpg')">
        
          </div>
          <!-- Slide Two - Set the background image for this slide in the line below -->
          <div class="carousel-item" style="background-image: url('img/slide22.jpg')">
          </div>
          <!-- Slide Three - Set the background image for this slide in the line below -->
          <div class="carousel-item" style="background-image: url('img/slide3.jpg')">
          </div>
        </div>
        <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
          <span class="carousel-control-prev-icon" aria-hidden="true"></span>
          <span class="sr-only">Previous</span>
        </a>
        <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
          <span class="carousel-control-next-icon" aria-hidden="true"></span>
          <span class="sr-only">Next</span>
        </a>
      </div>
    </header
    
     <!-- Page Content -->
    <div class="jumbotron">
      <h1 class="text-center">SARL COQUILLE</h1>
    </div>

    <!-- rest of my html -->
    
   </body>
  </html>

我使用此模板(如果有帮助)开始了我的项目,只是希望页面内容与标题重叠:https://blackrockdigital.github.io/startbootstrap-half-slider/

问题::将图片调整为〜0.5scd后的视口大小

经过测试的解决方案:使用位置而不是背景位置,调整我的图像尺寸(1900 * 1080),背景尺寸:自动100%,有些我忘记了(对不起!)

奇怪的行为:(对我来说很奇怪,因为我是菜鸟)第一张图片以理想的比例加载

有人可以给我一些建议吗?我已经阅读/观看了不同的教程,但是对我没有任何帮助,我也阅读了W3School文档,但这并没有真正帮助我...

对不起,我英语不好!

0 个答案:

没有答案