将固定顶部元素放在另一个引导程序4之上 [英] place fixed-top elements above one another bootstrap 4

查看:122
本文介绍了将固定顶部元素放在另一个引导程序4之上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让用户了解如何启用javascript以更好地使用网站,我希望使用bootstrap将消息放在导航栏上方,而是将它们相互堆叠。不介意我如何形容这一点。

I'm trying to let users get informed to enable javascript for better use of the website to I want the message placed above the navigation bar using bootstrap, but instead, they stack upon one another. Don't mind how I describe this.

我希望它们以这种方式放置:

I want them to be placed in this manner:

但它们以这种方式叠加在一起:

But they stack on top of each other this way:

使用Bootstrap 4,请提出任何意见吗?

Using Bootstrap 4, please any ideas?

以下是代码的部分内容

<html>
    ...
    <body>
        <noscript class='bg-danger text-light py-2 text-center d-block fixed-top mb-4' style='z-index: 9999;'>Enable javascript to use App better.</noscript>
        <header class='navbar fixed-top navbar-expand-lg navbar-light bg-light'>
            <div class='container'>
                ...
            </div>
        </header>
        ...
    </body>
</html>


推荐答案

在下面的代码中 div 部分:

<div class='bg-danger text-light py-2 text-center mb-0'>Enable javascript to enhance this App.</div>

需要替换为 noscript 。 div只是为了方便测试/可见性。

would need to be replaced with noscript. The div is just for easy testing/visibility.

为了使整个过程正常运行,你可以将所有内容移动到一个带有 fixed-top <的div中/ code> class然后添加你的 noscript 行,然后是navbar代码。

To make the whole thing work, you move everything into a div with the fixed-top class and then add your noscript line followed by the navbar code.

然后你还需要添加类似 style =margin-top:120px;的内容主容器将跟随 fixed-top div来推送主要内容。

Then you'll also need to add something like style="margin-top: 120px;" to the main container that would follow the fixed-top div to push the main content down.

点击运行代码摘要按钮下方并展开到整页:

Click the "run code snippet" button below and expand to full page:

<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>

<div class="fixed-top">
    <div class='bg-danger text-light py-2 text-center mb-0'>Enable javascript to enhance this App.</div>
    <nav class="navbar navbar-expand-lg navbar-light bg-light">
        <div class="container">
            <a class="navbar-brand" href="#">Navbar</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 mr-auto">
                    <li class="nav-item active">
                        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Link</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">
                            Dropdown
                        </a>
                        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                            <a class="dropdown-item" href="#">Action</a>
                            <a class="dropdown-item" href="#">Another action</a>
                            <div class="dropdown-divider"></div>
                            <a class="dropdown-item" href="#">Something else here</a>
                        </div>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link disabled" href="#">Disabled</a>
                    </li>
                </ul>
                <form class="form-inline my-2 my-lg-0">
                    <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
                    <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
                </form>
            </div>
        </div>
    </nav>
</div>

<p style="margin-top: 120px;">first line of text</p>

这篇关于将固定顶部元素放在另一个引导程序4之上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆