admin管理员组文章数量:1415491
So I am trying to create a left-sided nav bar, but after scrolling I can't get it to correctly stay to the left.
I have tried using:
position: fixed;
and
position: absolute;
However it cuts the width of the DIV down pletely.
To get a view of what I'm working with go to: http://198.50.242.77/YouBB/
I'd prefer to use strictly CSS only but if I must use JS I'll use it.
Thanks!
So I am trying to create a left-sided nav bar, but after scrolling I can't get it to correctly stay to the left.
I have tried using:
position: fixed;
and
position: absolute;
However it cuts the width of the DIV down pletely.
To get a view of what I'm working with go to: http://198.50.242.77/YouBB/
I'd prefer to use strictly CSS only but if I must use JS I'll use it.
Thanks!
Share Improve this question edited Aug 6, 2014 at 22:09 David Chalifoux asked Aug 6, 2014 at 22:02 David ChalifouxDavid Chalifoux 331 silver badge4 bronze badges 4- Please post all relevant CSS and HTML. It's hard I diagnose the problem with no code. If you have tried position fixed and that causes width issues, in my experience it's due to parent elements with % widths. I suggest reading up on papist ion fixed as it has some what unique behaviour. – speak Commented Aug 6, 2014 at 22:04
-
You should use
position
notdisplay
for this... ThatCSS
is not valid! – Steven Commented Aug 6, 2014 at 22:05 - 1 Seems fine to me, if you are talking about the white div on the left. It is responsive and get cut only on low resolutions, for which you can use CSS min-width property. Also, like the others said, it is position: fixed; – Boyan Hristov Commented Aug 6, 2014 at 22:06
- Sorry yes I meant position: fixed. – David Chalifoux Commented Aug 6, 2014 at 22:09
1 Answer
Reset to default 5position: fixed
is what you want. This causes the element to be removed from the flow entirely and stay in the same position even after scrolling the page.
position: absolute
is similar, but it only removes an element from the flow. Scrolling a containing div (or in this case, the whole page) will still cause it to move.
I opened up your web page in Chrome, and changed the styles for #navigation
to:
background: white;
height: 100%;
text-align: center;
position: fixed;
width: 18.72%;
This does what you want. You will just need to position the rest of the content to the right.
本文标签: javascriptMake a div stick to the left when scrollingStack Overflow
版权声明:本文标题:javascript - Make a div stick to the left when scrolling - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745164860a2645622.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论