简体   繁体   English

Bootstrap导航栏折叠异常除外的链接

[英]Bootstrap navbar collapse a links with exception not floating left

Hello I want to make a float none in my application scss for all the a href from the navbar with the exception of the navbar-brand which is the "Home". 您好,我想在我的应用程序scss中为导航栏上的所有href都设置浮点数,但导航栏品牌为“主页”。

This is my application.html.erb: 这是我的application.html.erb:

  <nav class="navbar navbar-default navbar-custom"> <div class="container"> <%= link_to "Home", root_path, class: "navbar-brand" %> <button class="navbar-toggle" data-toggle= "collapse" data-target=".navHeaderCollapse" > <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <div class="collapse navbar-collapse navHeaderCollapse" > <ul class="nav navbar-nav" id="top"> <li><%= link_to "Products", products_path %></li> <li><%= link_to "About the website", about_path %></li> </ul> <ul class="nav navbar-nav navbar-right"> <!-- the pull-right is like a float right --> <% if user_signed_in? %> <li><a><span class="current_user"> Current user: <%= @username %> </span></a></li> <li><%= link_to "Sign out", destroy_user_session_path, method: :delete %></li> <% else %> <li><a class="nav-link" data-toggle="modal" data-target="#login-modal">Log in</a></li> <li><a class="nav-link" data-toggle="modal" data-target="#signup-modal">Sign up</a></li> <% end %> </ul> </div> </div> </nav> 

And this is my application.scss: 这是我的application.scss:

 @media (max-width: 769px) { #top{ padding-top: 40px; } } @media (max-width: 769px) { a:not(.navbar-brand){ padding-top: 40px; float: none!important; } } 

The thing is that if I type: 问题是,如果我输入:

 @media (max-width: 769px) { a{ padding-top: 40px; float: none!important; } } 

It does what I want, by putting float none it works like kind of float left aligning all the a href to the left. 它实现了我想要的功能,通过不放置浮点数,它的工作方式类似于将所有a href对齐到左侧的浮点数。 BUT, as I said, I don't want it to do the same with the Home a href that has the class navbar-brand. 但是,正如我所说,我不希望它对具有navbar-brand类的Home a href做同样的事情。 That's the reason why I've tried with no success the a:not(.navbar-brand). 这就是为什么我没有成功尝试a:not(.navbar-brand)的原因。

You can add a separate rule for your Home menu item with class navbar-brand . 您可以使用navbar-brand类为“主”菜单项添加单独的规则。

@media (max-width: 769px) {
        a {
            float: none;
        }
        .navbar-brand {
            float: left;
        }
    }  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM