图片溢出carousel高度

来源:3-5 滚动图片广告

甘子12

2017-03-15 15:13

carousel设置了高度为500px;但是图片高度还是不受限制,超出了carousel的高度怎么回事儿?

写回答 关注

4回答

  • 她的周一
    2018-05-18 16:02:52

    你可以在浏览器看.item类容器的500px是否成功加上了,你的代码里是 .carousel.item 两个类名没有空格是交集选择器,并没有成功选择到 .carousel .item这个元素所以你的样式就没有加上去

    她的周一

    另外图片显示偏移可以考虑去掉.item里面的img,使用background-images加入图片

    2018-05-18 16:41:47

    共 1 条回复 >

  • 慕慕5461937
    2017-05-20 22:55:25

    http://img.mukewang.com/592058bc0001327914180749.jpg

    圈圈这里能看出来超出的部分;

    代码如下:

    <!DOCTYPE html>

    <html>

      <head>

        <meta charset="utf-8">

        <meta http-equiv="X-UA-Compatible" content="IE=edge">

        <meta name="viewport" content="width=device-width, initial-scale=1">

          <title>现在浏览器博物馆</title>

        <link href="css/bootstrap.min.css" rel="stylesheet">

        <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->

        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->

        <!--[if lt IE 9]>

          <script src="js/html5shiv.min.js"></script>

          <script src="js/respond.min.js"></script>

        <![endif]-->

        <style type="text/css">

          body{

            padding-top: 50px;

           }

          .carousel{

            height: 500px;

            background: #000;        

          }

          .carousel.item{

            height: 500px;

            background-color: #000;

          }

          .carousel-caption p{

            margin-bottom: 20px;

            font-size: 20px;

            line-height: 1.8;

          }

          .carousel img{

            width: 100%;

            height: 500px;      

          }

          


        </style>

      </head>

      <body>

      <nav class="navbar navbar-default navbar-fixed-top navbar-inverse" role="navigation">

      <div>

        <!-- Brand and toggle get grouped for better mobile display -->

        <div>

          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">

            <span>Toggle navigation</span>

            <span></span>

            <span></span>

            <span></span>

          </button>

          <a href="#">现代浏览器博物馆</a>

        </div>


        <!-- Collect the nav links, forms, and other content for toggling -->

        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

          <ul class="nav navbar-nav">

            <li><a href="#">综述</a></li>

            <li><a href="">简述</a></li>

              <li>

              <a href="#" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">特点 <span></span></a>

              <ul>

                <li><a href="#">Action</a></li>

                <li><a href="#">Another action</a></li>

                <li><a href="#">Something else here</a></li>

                <li role="separator"></li>

                <li><a href="#">Separated link</a></li>

                <li role="separator"></li>

                <li><a href="#">One more separated link</a></li>

              </ul>          

            </li>

            <li>

            <a href="#" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">关于<span></span></a>

            <ul>

            <li><a href="">关于我们</a></li>

            </ul>

            </li>

          </ul>

          

          </div><!-- /.navbar-collapse -->

      </div><!-- /.container-fluid -->

    </nav>

    <!--  轮播内容  -->

    <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">

      <!-- Indicators -->

      <ol>

        <li data-target="#carousel-example-generic" data-slide-to="0"></li>

        <li data-target="#carousel-example-generic" data-slide-to="1"></li>

        <li data-target="#carousel-example-generic" data-slide-to="2"></li>

        <li data-target="#carousel-example-generic" data-slide-to="3"></li>

      </ol>


      <!-- Wrapper for slides -->

      <div role="listbox">

        <div class="item active">

          <img src="img/1.jpg" alt="谷歌浏览器">

          <div>

            在一个带有层次的导航结构中标明当前页面的位置。各路径间的分隔符已经自动通过 CSS 的 :before 和 content 添加了

          </div>

        </div>

        <div>

          <img src="img/2.jpg" alt="...">

          <div>

            分页为您的网站或应用提供带有展示页码的分页组件,或者可以使用简单的翻页组件

          </div>

        </div>

        <div>

          <img src="img/3.jpg" alt="...">

          <div>

            徽章给链接、导航等元素嵌套元素,可以很醒目的展示新的或未读的信息条目。

          </div>

        </div>

        <div>

          <img src="img/4.jpg" alt="...">

          <div>

            适配导航元素的激活状态Bootstrap 内置的样式,让胶囊式导航内处于激活状态的元素所包含的徽章展示相匹配的样式。

          </div>

        </div>

        

      </div>


      <!-- Controls -->

      <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">

        <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>

        <span>上一页</span>

      </a>

      <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">

        <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>

        <span>下一页</span>

      </a>

    </div>

       <!--  轮播内容  -->

      </body>  

        <script src="js/jquery-3.2.1.min.js"></script>

         <script src="js/bootstrap.min.js"></script>

    </html>


  • 慕慕5461937
    2017-05-20 22:52:15

    按照“在.carousel img的样式里设置height”也不行啊;还是超出来了!~~

  • qq_寒冰_2
    2017-03-24 11:34:57

    图片本身具有长宽比例,设置.carousel img的width:100%后,图片的宽度被自动扩到屏幕的宽,高度也会按相同的比例拉伸,carousel设置的高度只是说放图片的div的高度并不是图片本身的高度,要设置图片的高度,也要在.carousel img的样式里设置height样式才行

基于bootstrap的网页开发

Bootstrap框架的基础教程,学会用Bootstrap前端框架搭建网页

187681 学习 · 734 问题

查看课程

相似问题