<img/>与地址栏一起使用

时间:2018-05-04 00:58:36

标签: html css twitter-bootstrap image

我正在尝试为带有图像的标题制作旋转木马。我使用BOOTSTRAP 4作为框架来使轮播工作

 <div id="aboutMe" class="carousel slide pt-1 container-fluid" data-ride="carousel">
     <!-- Carousel indicators --> 
       <ul class="carousel-indicators">
          <li data-target="#" class="active"></li>
          <li data-target="#"></li>
          <li data-target="#"></li>
       </ul>
       <!-- slide --> 
         <div class="carousel-inner">
             <div class="carousel-item active">
                <img style="background-image:url(https://images.unsplash.com/photo-1506882741710-98761c574b48?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=794de1f3a10ddf74c928e6cebd1aa55e&auto=format&fit=crop&w=1050&q=80)" alt="The Chicago Theater">
             </div>
          </div>
        </div>

我要做的是让我的图像覆盖容器,随着容器变小或变大,图像在旋转木马中调整大小

2 个答案:

答案 0 :(得分:1)

首先,您需要确保使用正确的<HTML>格式,并在<script src = 'bootstrap css link'>内使用<head>,并在<body>中使用

 <div id="aboutMe" class="carousel slide" data-ride="carousel">
 <!-- Carousel indicators --> 
   <ul class="carousel-indicators">
      <li data-target="#" class="active"></li>
      <li data-target="#"></li>
      <li data-target="#"></li>
   </ul>
   <!-- slide --> 
     <div class="carousel-inner">
         <div class="carousel-item active">
            <img src="https://images.unsplash.com/photo-1506882741710-98761c574b48?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=794de1f3a10ddf74c928e6cebd1aa55e&auto=format&fit=crop&w=1050&q=80" alt="The Chicago Theater" style="width:100%;">
         </div>
      </div>
    </div>

答案 1 :(得分:0)

您正在将图像用作带有内嵌样式的背景图像。你应该像这样添加图像

.carousel-item img {
  width: 100% !important;
  height: 100vh !important;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<div id="aboutMe" class="carousel slide pt-1 container-fluid" data-ride="carousel">
  <!-- Carousel indicators -->
  <ul class="carousel-indicators">
    <li data-target="#aboutMe" data-slide-to="0" class="active"></li>
    <li data-target="#aboutMe" data-slide-to="1"></li>
    <li data-target="#aboutMe" data-slide-to="2"></li>
  </ul>
  <!-- slide -->
  <div class="carousel-inner active">
    <div class="carousel-item active">
      <img src="https://images.unsplash.com/photo-1506882741710-98761c574b48?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=794de1f3a10ddf74c928e6cebd1aa55e&auto=format&fit=crop&w=1050&q=80" alt="The Chicago Theater">
    </div>
    <div class="carousel-item">
      <img src="https://images.unsplash.com/photo-1506882741710-98761c574b48?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=794de1f3a10ddf74c928e6cebd1aa55e&auto=format&fit=crop&w=1050&q=80" alt="The Chicago Theater">
    </div>
    <div class="carousel-item">
      <img src="https://images.unsplash.com/photo-1506882741710-98761c574b48?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=794de1f3a10ddf74c928e6cebd1aa55e&auto=format&fit=crop&w=1050&q=80" alt="The Chicago Theater">
    </div>
  </div>

  <!-- Left and right controls -->
  <a class="carousel-control-prev" href="#aboutMe" data-slide="prev">
    <span class="carousel-control-prev-icon"></span>
  </a>
  <a class="carousel-control-next" href="#aboutMe" data-slide="next">
    <span class="carousel-control-next-icon"></span>
  </a>
</div>