简体   繁体   English

当所有内容在浏览器窗口中可见时,如何使div更改为固定位置?

[英]How to make div change to fixed position when all content is visible in browser window?

Not sure if the title made sense, but I noticed in the wordpress 3.8.1 admin panel, If you resize your window to where the sidebar has menu items blocked from view, it is normal positioning, which allows the sidebar to scroll. 不确定标题是否有意义,但是我在wordpress 3.8.1管理面板中注意到,如果将窗口的大小调整到侧栏阻止菜单项可见的位置,这是正常位置,这允许侧栏滚动。

If all the items are visible, then the sidebar has fixed positioning so that only the content to the right of the sidebar will scroll. 如果所有项目均可见,则侧边栏具有固定的位置,因此仅侧边栏右侧的内容将滚动。

Neat little effect. 收效甚微。

I was thinking it requires jQuery to add a class or change css. 我以为它需要jQuery添加一个类或更改CSS。 Maybe if the last item in the sidebar is visible then add the class, else leave it alone. 也许如果侧边栏中的最后一项可见,则添加类,否则将其保留。

Not sure how to actually code that though. 不确定如何实际编码。

Can someone help out, maybe even a basic fiddle? 有人可以帮忙,甚至是基本的小提琴吗?

You can do this with simple CSS. 您可以使用简单的CSS做到这一点。

.div_name {
position:fixed;
}

check W3schools Position fixed property for tags 检查W3schools位置固定属性以获取标签

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

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