html - Bootstrap 4 轮播 - 响应行为

标签 html css bootstrap-4

我正在尝试创建一个顶部带有透明导航栏的全屏 bootstrap 4 旋转木马。以下代码有效。

HTML:

<!doctype html>
<html lang="ro">
    <!-- START head -->
    <head>
        <!-- START meta -->
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <!-- END meta -->
        <!-- START CSS -->
        <link rel="stylesheet" href="resources/vendor/bootstrap-4.0.0/bootstrap.min.css">
        <link rel="stylesheet" href="resources/vendor/bootstrap-4.0.0/bootstrap-reboot.min.css">
        <link rel="stylesheet" href="resources/vendor/fontawesome-5.0.4/css/fontawesome-all.min.css">
        <link rel="stylesheet" href="resources/custom/css/index.css">
        <!-- END CSS -->
    </head>
    <body>
        <!-- START navbar -->
        <nav class="navbar navbar-expand-sm container navbar-dark fixed-top">
            <a class="navbar-brand" href="#">SMART RECRUIT</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <ul class="navbar-nav ml-auto">
                    <li class="nav-item active">
                        <a class="nav-link" href="#">Acasa<span class="sr-only">(current)</span></a>
                    </li>
                    <li class="nav-item d-none d-md-block">
                        <a class="nav-link" href="#">Despre noi</a>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        Servicii
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                            <a class="dropdown-item" href="#">Pentru candidati</a>
                            <div class="dropdown-divider"></div>
                            <a class="dropdown-item" href="#">Pentru companii</a>
                        </div>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Parteneri</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Contact</a>
                    </li>
                </ul>
            </div>
        </nav>
        <!-- END navbar -->
        <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel" data-interval="3000">
            <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">
                    <div style="max-height: 100vh; width: 100%;">
                        <img class="d-block img-fluid w-100" src="resources/custom/img/1.jpg" alt="First slide">
                    </div>
                </div>
                <div class="carousel-item">
                    <div style="max-height: 100vh; width: 100%;">
                        <img class="d-block w-100" src="resources/custom/img/2.jpg" alt="Second slide">
                    </div>
                </div>
                <div class="carousel-item">
                    <div style="max-height: 100vh; width: 100%;">
                        <img class="d-block w-100" src="resources/custom/img/3.jpg" alt="Third slide">
                    </div>
                </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>
        <!-- START JAVASCRIPT -->
        <script src="resources/vendor/jquery-3.3.1/jquery-3.3.1.min.js"></script>
        <script src="resources/vendor/tether-1.3.3/tether-1.3.3.min.js"></script>
        <script src="resources/vendor/bootstrap-4.0.0/bootstrap.min.js"></script>
        <!-- END JAVASCRIPT -->
    </body>
</html>

example js fiddle

但是,存在一些问题: - 强制图像全屏显示。 - 调整大小会导致图像的高度不同。

是否有任何选项可以让轮播在大屏幕上全屏显示并在调整大小时使所有图像的宽度相等而不影响响应能力?

最佳答案

尝试给 img 添加高度:

style="height: 100vh"

它将使图像在不同的屏幕尺寸上全屏显示

希望对您有所帮助!

关于html - Bootstrap 4 轮播 - 响应行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48417524/

相关文章:

html - 带有图像图案的 SVG 仅适用于 Chrome

html - 将大量参数传递给 Controller ​​?

html - float 无序列表 - 适用于 jfiddle 而不是浏览器(尝试更新 chrome 和 firefox)

html - 不确定长度的文本和 HTML/CSS 中的行 "right"方式

HTML/CSS svg 自动高度和宽度

css - JQuery Mobile + Knockout,CSS 样式失败

mobile - 移动浏览器的网站 : CSS and meta tags

html - 如何使我的 Bootstrap 4 导航栏下拉菜单全宽?

html - 为什么我的图像没有出现在其他 View 中? (导轨)

css - 为什么我使用 Bootstrap 4 在顶行和导航栏之间有一个空格?