简体   繁体   English

制定一个固定的响应式div

[英]Make a fixed and responsive div

I have this design made using bootstrap there is a left side bar 100% in height. 我使用引导程序进行了这种设计,左侧栏杆的高度为100%。 And there is a content area on the left. 左侧有一个内容区域。 The left sidebar is fixed using position : fixed so it stays fixed when scrolling down. 左侧边栏使用position:fixed固定,因此在向下滚动时保持不变。 It's fine on desktop. 在台式机上很好。

However when it's being viewed from mobile the the fixed sidebar goes to the top like in any other responsive design. 但是,从移动设备进行查看时,固定侧边栏会像其他任何响应式设计一样移至顶部。 Fine. 精细。 But the content area on the right in desktop comes on top of the sidebar not bottom to it cause the position : fixed. 但是,桌面右侧的内容区域位于侧栏的顶部,而不是其底部,从而导致位置:固定。

How can i fix it? 我该如何解决? Keep the sidebar fixed in desktop and make it responsive on mobile? 将侧边栏固定在桌面上,并使其在移动设备上响应?

Sorry i'm being on mobile 抱歉,我正在使用手机

html HTML

<div class='col-md-3' id='sidebar'>Sidebar</div>
<div class='col-md-9'>
content
</div>

css CSS

#sidebar 
{
 height :100%;
 position : fixed;
 }
html,body
 { 
 height : 100%;
 }

Suggestion: use @media queries 建议: 使用@media查询

@media (max-width: 768px) { /* mobile view */
  #sidebar  {
    position: relative;
    // or any other property to achieve the desired
  }
}

MDN CSS/Media_queries MDN CSS / Media_queries
Css-Tricks Suggested Standard Media Sizes CSS技巧建议的标准媒体尺寸

You must be using 'position: fixed;' 您必须使用“ position:fixed;” instead if 'absolute' due to some layout issue faced in Safari or Chrome on Mac! 相反,如果是Safari或Mac上的Chrome遇到某些布局问题,则为“绝对”! I also faced this problem in an app. 我在一个应用程序中也遇到了这个问题。 Try to search the solution on Chrome Developers forum. 尝试在Chrome开发者论坛上搜索解决方案。

It is tough to diagnose without more to go from, however you oculd try the following: 没有更多信息很难诊断,但是您可以尝试以下方法:

On #sidebar instead of using height: 100%; #sidebar而不是使用height: 100%; use: 采用:

top: 0;
bottom: 0;
left: 0;

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

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