【问题标题】:Bootstrap top navbar blocking my content laravel引导顶部导航栏阻止我的内容 laravel
【发布时间】:2018-04-30 16:50:32
【问题描述】:

我对导航栏有疑问。刚才当我能够让导航栏在滚动时粘在顶部时,顶部的内容就挡住了我的视线,我实际上用这个问题来帮助我,但它没有用,还有其他解决方案还是我只是把它放在错误的地方?这是我曾经帮助过我的问题,Twitter Bootstrap - top nav bar blocking top content of the page

我尝试使用以下代码,但没有帮助:

body {
  padding-top: 60px;
}
@media (max-width: 979px) {
  body {
    padding-top: 0px;
  }
}

这就是发生的事情

代码如下:

app.blade.php(我的导航栏在哪里)

<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

   <title>@yield('title')</title>

    <!-- Styles -->
    <link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
<body>
    <div id="app">
        <nav class="navbar navbar-default navbar-static-top">
            <div class="container-fluid" style="background-color: blue">
                <div class="navbar-header" style="padding-left: 50px">

                    <!-- Collapsed Hamburger -->
                    <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#app-navbar-collapse" aria-expanded="false">
                        <span class="sr-only">Toggle Navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    @include('layouts.testSidebar')

                    <!-- Branding Image -->
                    <a class="navbar-brand" href="{{ url('/') }}" style="color: white">
                        @yield('title')
                    </a>
                </div>



                <div class="collapse navbar-collapse" id="app-navbar-collapse">
                    <!-- Left Side Of Navbar -->
                    <ul class="nav navbar-nav">
                        &nbsp;
                    </ul>


                    <!-- Right Side Of Navbar -->
                    <ul class="nav navbar-nav navbar-right">
                        <!-- Authentication Links -->
                        @guest
                            <li><a href="{{ route('login') }}">Login</a></li>
                            <li><a href="{{ route('register') }}">Register</a></li>
                        @else
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" style="background-color:blue">
                                    <b style="color: white">{{ Auth::user()->name }}</b> <span class="caret"></span>
                                </a>

                                <ul class="dropdown-menu" style="background-color: blue">
                                    <li>
                                        <a href="{{ route('logout') }}"
                                            onclick="event.preventDefault();
                                                     document.getElementById('logout-form').submit();" style="background-color: blue">
                                            <b style="color: white">Logout</b>
                                        </a>

                                        <form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
                                            {{ csrf_field() }}
                                        </form>
                                    </li>
                                </ul>
                            </li>
                        @endguest
                    </ul>
                </div>
            </div>
        </nav>

        @yield('content')
    </div>

    <!-- Scripts -->
    <script src="{{ asset('js/app.js') }}"></script>

</body>
</html>

test.css(这是我的侧边栏代码,我认为不需要侧边栏代码,所以我只放了 css,因为它也会影响导航栏)

body{
    margin:0px;
    padding:0px;
    font-family:"Helvetica Neue", Helvetica, Arial;
    padding-top: 65px; 
    }
@media (max-width: 979px) {
  body {
    padding-top: 0px;
  }
}



#sidebar{
    background:blue;
    width:200px;
    height:100%;
    display:block;
    position:fixed;
    left:-200px;
    top:0px;
    transition:left 0.3s linear;
}

#sidebar.visible{
    left:0px;
    transition:left 0.3s linear;
}

ul{
    margin:0px;
    padding:0px;
}

ul li{
    list-style:none;
}

ul li a{
    background:#0000FF;
    color:white;
    border-bottom:1px solid #111;
    display:block;
    width:180px;
    padding:10px;
    text-decoration: none;
}

#sidebar-btn{
    display:inline-block;
    vertical-align: middle;
    width:20px;
    height:15px;
    cursor:pointer;
    margin:20px;
    position:absolute;
    top:0px;
    right:-60px;
}

#sidebar-btn span{
    height:1px;
    background:white;
    margin-bottom:5px;
    display:block;
}

#sidebar-btn span:nth-child(2){
    width:75%;
}

#sidebar-btn span:nth-child(3){
    width:50%;
}

#navbar-toggle collapsed{
    background:#0000FF;
}

.navbar {
    background:#0000FF;
    position: fixed;
    width: 100%;
}


nav.sidebar .navbar-nav .open .dropdown-menu>li>a:hover, 
nav.sidebar .navbar-nav .open .dropdown-menu>li>a:focus {
    color: white;
    background-color: transparent;
}

#test .dropdown-menu {
    position: absolute;
    top: 0;
    left: 180px;
    min-width: 180px;
}

【问题讨论】:

  • 您是否阅读过有关固定导航栏的引导文档,当他们说:确保在核心引导 CSS 之后包含此内容。? (重点在文档中)您确定 css 以正确的顺序加载吗? getbootstrap.com/docs/3.3/components/…
  • 是的,我已经按照文档进行操作,但是当我尝试做顶部填充时,它会给我一个很大的空白空间,所以我根据我发现的问题使用了这 2 个解决方案,margin:0px 和还有@media(最大宽度)。而且当我尝试将它放在我的内容正文中时,它仍然会阻止他们的内容

标签: php css laravel


【解决方案1】:

尝试添加“padding-top: 60px;”样式到包裹“@yield('content')”区域的任何元素,而不是 body 元素。希望这会将您的内容推送到绝对定位的导航栏下方。

【讨论】:

  • 你的意思是像
    @yield('content')
  • 哦,是的,这项工作,我想我太专注于 body 标签,我忘记了主要重要的事情是在 @yield ('content') 部分。非常感谢您的帮助:)
猜你喜欢
  • 2012-05-07
  • 2015-08-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-12
  • 2021-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多