Resize width of Position:Fixed div to make it responsive / fluid

痴心易碎 提交于 2019-12-11 21:25:33

问题


I have a sidebar to which I am attaching a fixed class to make it sticky on scroll.

.fixed { position:fixed;top:0;bottom: 45px;min-height: 0 !important; }

But once the class gets activated the sidebar width is not working and so its messing the responsive layout once we start scrolling.

DEMO: http://jsfiddle.net/FyrRm/

I am not sure how to resize the fixed:position sidebar to fit it responsively. I tried using calc but it didn't work.

Any ideas?


回答1:


UPDATED Didn't take into account resizing from smaller to bigger


Add this to $(document).ready:

$(window).resize(function() {
        $(".sticky").width($("#sidebar > img").width());
}).resize();

DEMO



来源:https://stackoverflow.com/questions/21144454/resize-width-of-positionfixed-div-to-make-it-responsive-fluid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!