简体   繁体   English

如何在引导程序中向轮播添加背景图像

[英]how to add background image to carousel in bootstrap

Respected Devs, 尊敬的开发人员,

I'm new to website development, I wanted to have a carousel effect on hero, so I copied it from this site , it's cool though. 我是网站开发的新手,我想对英雄有一个轮播效果,所以我从这个网站复制了它,虽然很酷。

I want to reduce the opacity of the hero by adding background-image with linear-gradient of (0,0,0,0.7) on both sides to have effect like this, 我想通过在两侧添加线性渐变为(0,0,0,0.7)背景图像来减少英雄的不透明感,

图片

so I removed the src tag and added the image link in div tag, But, it dosen't seem to work, the image doesn't show up on page. 所以我删除了src标签,并在div标签中添加了图片链接,但是,它似乎没有用,图片没有显示在页面上。

Here's my code 这是我的代码

<div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
  <div class="carousel-inner">
    <div class="carousel-item active" style="background-image: url('image/must.jpg'), linear-gradient(rgba(0,0,0,0.7), rgba(0,0,0,0.7));">
      <!--<img src="image/must.jpg" class="d-block w-100" alt="...">-->
    </div>
    <div class="carousel-item">
      <img src="image/shelby1.jpg" class="d-block w-100" alt="...">
    </div>
  </div>
  <a class="carousel-control-prev" href="#carouselExampleControls" 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="#carouselExampleControls" role="button" data-slide="next">
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>

help me.. 帮我..

html: 的HTML:

 <div class="item">
          <img src="images/pic2.jpg" alt="pic 2">
          <div class="carousel-caption">
            <h1>Web Desgin</h1>
         </div>
            </div>

css: CSS:

.item img {
    position: absolute;
    object-fit:cover;
    width: 100%;
    top: 0;
    left: 0;
    min-height: 572px;
    background:rgba(0,0,0,0.7);
}  

i hope it will help you 希望对您有帮助

The style attributes you used should have worked, but it looks like you did a mess, anyway in order to achieve what you want you have to remove all the stuff and create one from scratch using getbootstrap.com carousel reference and the effect that you want will work by adding the below code. 您使用的样式属性应该可以正常工作,但是看起来好像一团糟,为了实现所需的功能,您必须删除所有内容并使用getbootstrap.com轮播参考以及所需的效果从头开始创建内容通过添加以下代码即可工作。

<div class="carousel-item active" style="background-image: url('image/must.jpg'), linear-gradient(rgba(0,0,0,0.7), rgba(0,0,0,0.7));">

There is also one more cool responsive carousel effect repository called Owl Carousel on github they also have included how to give different effects on carousel like: swipe drag right to left with continuous loop and it's fully customizable check it out, it's cool. github上还有一个更酷的响应式轮播效果存储库,名为Owl Carousel ,它们还包括如何对轮播产生不同的效果,例如:用连续循环从右向左 滑动 拖动 并且完全可自定义检查它,很酷。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM