Twitter Bootstrap导航栏固定 [英] Twitter Bootstrap Navigation Bar Fixed

查看:137
本文介绍了Twitter Bootstrap导航栏固定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当屏幕尺寸小于940像素时,我必须更改哪些导航栏才能固定?我不想让它响应。如果你调整你的浏览器窗口在940px下你会看到scroolbar-x(底部滚动条)出现,但当你滚动到右边,导航栏位置仍然是固定的,一些菜单不会出现。





也许有些图片会解释我的问题。



你给的例子(Twitter)有navbar固定位置和固定大小。固定位置意味着滚动条不会影响导航条的位置,这就是为什么你不能使用x滚动条来查看导航条的一部分,一旦它小于940px宽,被隐藏在下浏览器窗口的右边框。



因此您必须选择


  1. 位置,固定大小导航栏,无论用户向下滚动多少,并且接受在足够小的屏幕下,它们将不能水平滚动以查看它all,OR

  2. 有一个固定位置流体尺寸导航栏,可调整其宽度以适应不同的屏幕尺寸,或者

  3. 具有非固定位置
  4. / em>固定大小的导航栏,它会响应水平滚动,但是当用户向下滚动页面时不会显示。

有效地,你不能让位置在x方向单向工作,在y方向单向工作。



通过使用CSS检查器在Twitter页面中编辑以下类,您可以看到选项2的意思:

  .global-nav .container {
width:auto;
max-width:865px;
}
.global-nav,.global-nav-outer {
height:auto;
}

第二个选择器在内容无法容纳时



通过进行以下更改,您可以看到选项3的意思:

  .topbar {
position:absolute;
/ * ...其余为* /
}






EDIT



当然,它不能在CSS中完成,并不意味着它不能完成。这里是一个jsfiddle实现你提到的脚本。这使用MooTools而不是我通常用于bootstrap的jQuery。



小提琴: http://jsfiddle.net/uadDW/4/

全屏版本,以更好地看到效果: http://jsfiddle.net/uadDW/4/show/



>(感谢@Sherbrow为我提供了一个基础的小提琴,我做了这一个)。


What I must change to make the navigation bar fixed when screen size under 940px? I don't want to make it responsive. If you resize your browser windows under 940px you will see that scroolbar-x (bottom-scrollbar) appear, but when you scroll it to the right, the navigation bar position still fixed, and some menu won't appear.

Maybe some picture will explain what my problem.

解决方案

This can't be done in CSS alone.

The example you give (Twitter) has the navbar with fixed position AND fixed size at all screen sizes. Fixed position means that the scrollbars will not affect the position of the navbar, and this is why you can't use the x-scrollbar to see the part of the navbar which, once it's less than 940px wide, is hidden 'under' the right border of the browser window.

So you have to choose, either

  1. Have a fixed position, fixed size navbar which is present at the top no matter how far the user scrolls down and accept that under a small enough screen they won't be able to scroll horizontally to see it all, OR
  2. Have a fixed position, fluid size navbar which adjusts its width to accommodate different screen sizes, which will hopefully mitigate the need to scroll horizontally in the first place, especially if you let it grow vertically if its contents don't fit in one row, OR
  3. Have a non-fixed position, fixed size navbar which will respond to horizontal scrolling but will not be ever-present when the user scrolls down the page.

Effectively, you can't have position work one way in the x direction and another in y.

You can see what I mean by option 2 by editing the following classes in the Twitter page using the CSS inspector:

.global-nav .container {
    width: auto;
    max-width: 865px;
}
.global-nav, .global-nav-outer {
    height: auto;
}

The second selector implements the vertical fluidity for once the contents can't fit in one row.

You can see what I mean by option 3 by making these changes:

.topbar {
    position: absolute;
    /* ... the rest as is */
}


EDIT

Of course, that it can't be done in CSS doesn't mean it can't be done at all. Here's a jsfiddle implementing that script you mentioned. This uses MooTools as opposed to jQuery, which I normally use with bootstrap.

The fiddle: http://jsfiddle.net/uadDW/4/
Full screen version to better see the effect: http://jsfiddle.net/uadDW/4/show/

(Thanks to @Sherbrow for providing the base fiddle with which I made this one).

这篇关于Twitter Bootstrap导航栏固定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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