html - 如何在 bootstrap carousel 上正确调整图像大小

标签 html twitter-bootstrap carousel

我无法将这些图片裁剪以适合轮播。我认为这一行需要以某种方式进行编辑:

忽略: 它告诉我添加更多细节,所以我输入额外的东西来绕过它,就像一个坏人会采取简单的方法而不是添加实际信息,而是一些对帖子没有任何值(value)的 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>

最佳答案

这是一个 JS Fiddle使用来自各种来源的测试图像,这些图像具有不同的尺寸,但它们正确地适合轮播。这是你要找的吗?

相关代码改动:

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

如果您取出上面的 CSS,您将看到轮播如何调整其中图像的大小。是的,通过将高度限制为 300 像素, 图像可能看起来很模糊,但足以适应轮播。

如果这有帮助,请告诉我。如果没有,如果你也能提供图片就好了。

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

希望这能奏效。 :)

关于html - 如何在 bootstrap carousel 上正确调整图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47578612/

相关文章:

javascript - 在我的 slider 下方添加导航按钮

javascript - 想要将添加的元素移动到 DOM 的不同部分

html - 宽度高度乘以内容高度

html - 如何为一个div添加滚动条,2个div始终可见

twitter-bootstrap - Bootstrap 进度条不会在 react 组件内呈现

html - 在 Bootstrap 中,如何在 sm 模式下将按钮设置为 "Stack"

php - 通过 PHP + HTML 从 MySQL 数据库中选择数据创建表

twitter-bootstrap - 如何打印 Bootstrap 轮播中的所有项目

jquery - 如何获取轮播的总幻灯片数和当前幻灯片数

c# - Xamarin.Forms.CarouselView 按钮的下一个和上一个项目事件