我需要在移动设备上隐藏旋转木马

时间:2018-02-18 19:48:22

标签: twitter-bootstrap carousel bootstrap-4

我有一个内置Bootstrap 4的旋转木马,我想在移动设备上隐藏它。我该怎么做?

<!--Carousel Wrapper-->
<div id="carousel-example-3" class="carousel carousel-fade white-text" data-ride="carousel" data-interval="false">
    <!--Indicators-->
    <ol class="carousel-indicators">
        <li data-target="#carousel-example-3" data-slide-to="0" class="active"></li>
        <li data-target="#carousel-example-3" data-slide-to="1"></li>
        <li data-target="#carousel-example-3" data-slide-to="2"></li>  
    </ol>
    <!--/.Indicators-->
    <!--Slides-->
    <div class="carousel-inner" role="listbox">
        <!-- First slide -->
        <div class="carousel-item active view hm-black-light" style="background-image: url(img/service1.jpg); background-repeat: no-repeat; background-size: cover;">
        </div>
        <!-- /.First slide -->
        <!-- Second slide -->
        <div class="carousel-item view hm-black-light" style="background-image: url(img/service2.jpg); background-repeat: no-repeat; background-size: cover;" ">
        </div>
        <!-- /.Second slide -->
        <!-- Third slide -->
        <div class="carousel-item view hm-black-light "  style="background-image: url(img/service5.jpg); background-repeat: no-repeat; background-size: cover; ">
        </div>
        <!-- /.Third slide -->
    </div>
    <!--/.Slides-->
</div>
<!--/.Carousel Wrapper-->

1 个答案:

答案 0 :(得分:0)

要在移动设备上完全隐藏轮播,请将类d-none d-md-block添加到父元素,如下面的代码段所示。

d-none(显示:无)将从最小屏幕尺寸开始隐藏整个事物,d-md-block类(显示:块)将从媒体显示它(md )屏幕尺寸及以上。

以下是代码段(单击下面的“运行代码段”按钮并展开到整页):

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<p class="mt-3">The following carousel is hidden on screens that are smaller than medium ('md'):</p>

<div id="carouselExampleIndicators" class="carousel slide d-none d-md-block" data-ride="carousel">
    <ol class="carousel-indicators">
        <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
        <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
        <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
    </ol>
    <div class="carousel-inner">
        <div class="carousel-item active">
            <img class="d-block w-100" src="https://placeimg.com/1080/500/animals" alt="First slide">
            <div class="carousel-caption d-none d-md-block">
                <h5>My Caption Title (1st Image)</h5>
                <p>The whole caption will only show up if the screen is at least medium size.</p>
            </div>
        </div>
        <div class="carousel-item">
            <img class="d-block w-100" src="https://placeimg.com/1080/500/arch" alt="Second slide">
        </div>
        <div class="carousel-item">
            <img class="d-block w-100" src="https://placeimg.com/1080/500/nature" alt="Third slide">
        </div>
    </div>
    <a class="carousel-control-prev" href="#carouselExampleIndicators" 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="#carouselExampleIndicators" role="button" data-slide="next">
        <span class="carousel-control-next-icon" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
    </a>
</div>

顺便说一句,代码中存在无效的HTML。你可能想解决这个问题。