如何在boostrap旋转木马上正确调整图像大小

时间:2017-11-30 16:54:15

标签: html twitter-bootstrap carousel

我无法将这些图像切碎以适应旋转木马。我认为这条线需要以某种方式进行编辑:

IGNORE: 它告诉我要添加更多的细节,所以我输入额外的东西,通过它像一个坏人会采取简单的方法,而不是添加实际的信息,而是一些没有增加任何价值的bs

这是我写得很糟糕的代码:

<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" 
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script 
src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
<script 
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"> 
</script>
</head>
<body>
<style>
h1{
    color: aqua;
    font-size: 40px;
    text-align: center;
    font-style: italic; 

} 


</style>

<!-- this creates the menu -->
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">Mason Cox</a>
</div>
 <ul class="nav navbar-nav">
  <li><a href="Cox_Mason_jumbotron.html">Jumbotron</a></li>
  <li class="active"><a href="Cox_Mason_carousel.html">Carousel</a></li>
  <li><a href="Cox_Mason_responsive_table.html">Table</a></li>
 </ul>
 </div>
</nav>
<!--this is the heading-->
<h1>Mason Cox</h1>

<!--this is the carousel-->
<div class="container">
<h2>Friends and I Carousel</h2>  
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
  <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
  <li data-target="#myCarousel" data-slide-to="1"></li>
  <li data-target="#myCarousel" data-slide-to="2"></li>
    <li data-target="#myCarousel" data-slide-to="3"></li>
  <li data-target="#myCarousel" data-slide-to="4"></li>
<li data-target="#myCarousel" data-slide-to="5"></li>
</ol>

<!-- Wrapper for slides -->
<div class="carousel-inner">
  <div class="item active">
    <img src="leahandi.jpg" alt="dance"  style="width:75%;" 
   style="height:25%;">
      <div class="carousel-caption">
      <h3>My girlfriend and I at a dance.</h3>
      </div>
  </div>

  <div class="item">
    <img src="padre.png" alt="padre" style="width:100%;">
      <div class="carousel-caption">
      <h3>Friends and I at a bar in South Padre</h3>
      </div>
  </div>

  <div class="item">
    <img src="homepage.PNG" alt="oldpic" style="width:100%;">
      <div class="carousel-caption">
      <h3>A picture of me frshman year</h3>
      </div>
  </div>

    <div class="item">
    <img src="tailgate.jpg" alt="tailgate" style="width:100%;">
        <div class="carousel-caption">
      <h3>My girlfriend and I at a tailgate.</h3>
      </div>
  </div>

  <div class="item">
    <img src="me.PNG" alt="topgolf" style="width:100%;">
      <div class="carousel-caption">
      <h3>A picture of me at Top Golf</h3>
      </div>
  </div>

  <div class="item">
    <img src="friends.JPG" alt="friend group" style="width:100%;">
      <div class="carousel-caption">
      <h3>A picture of friends and I from last year</h3>
      </div>
  </div>
</div>

<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
  <span class="glyphicon glyphicon-chevron-left"></span>
  <span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
  <span class="glyphicon glyphicon-chevron-right"></span>
  <span class="sr-only">Next</span>
</a>
 </div>
 </div>


</body>
</html>

1 个答案:

答案 0 :(得分:1)

这里有JS Fiddle使用来自不同来源的测试图像,这些图像具有不同的尺寸,但它们恰好适合旋转木马。这是你正在寻找的吗?

相关代码更改

div.carousel div.item > img {
  width: 100%;
  height: 300px;
}

如果你拿出上面的CSS,你会看到轮播如何获取图像的大小。通过将高度限制为300px,是的,图像可能看起来模糊,但非常适合放入旋转木马。

如果这有帮助,请告诉我。如果没有,如果你也可以提供图像,那就太好了。

IGNORE:与图像对应的图像标题。没有意义。

希望这有效。 :)