简体   繁体   English

右面板,底部有div

[英]Right panel with div at bottom

To make it simple: I have a page with a div as right panel 简单起见:我有一个带有div作为右面板的页面

.rightPanel{
  position: fixed;
  right: 0px;
}

This panel has aa few div inside (header, titles, etc.) and a div with the body. 该面板内部有一些div (标题,标题等),以及带有主体的div I need an extra div at the bottom where I will place the action bar. 我需要在底部放置一个额外的div ,以放置操作栏。

I have tried 我努力了

.actionBar{
  position: absolute;
  bottom: 20px;
}

The problem with this approach is that when the body is too big, the action bar will be on top of it. 这种方法的问题在于,当身体太大时,动作栏将位于其上方。 I would like a scroll bar on the body, if needed, with the action bar always fixed at the bottom. 我需要一个滚动条,如果需要的话,将动作条始终固定在底部。

<div class="rightPanel">
  <header> .. </header> 
  <div class="body"> .. </div>
  <div class="actionBar"> .. </div>
</div>

I don't want to give a fixed height to the body as it is dynamically crated. 我不想给身体一个固定的高度,因为它是动态装箱的。

Use flexbox to have a dynamic middle section. 使用flexbox具有动态的中间部分。 Here's a working demo: 这是一个工作示例:

 body { padding: 0; margin: 0; } .rightPanel { display: flex; flex-direction: column; position: fixed; right: 0px; width: 200px; height: 100%; border: 1px solid blue; } header { width: 100%; height: 30px; border: 1px solid red; } .body { flex-grow: 1; width: 100%; height: 100%; overflow: auto; } .actionBar { width: 100%; height: 30px; border: 1px solid red; } 
 <div class="rightPanel"> <header> this is the header </header> <div class="body"> "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." </div> <div class="actionBar"> this is the action bar </div> </div> 

JSFiddle: https://jsfiddle.net/x52rq6du/1/ JSFiddle: https ://jsfiddle.net/x52rq6du/1/

You can use clear property. 您可以使用clear属性。

The clear property tells on which sides of an element floating elements cannot float. clear属性指示浮动元素不能在元素的哪一侧浮动。

By using both value for clear. 通过同时使用两个值进行清除。 You can specify no element can float neither on right nor left side of the element. 您可以指定没有元素不能在元素的右侧或左侧浮动。 like below: 如下所示:

   .actionBar{
      position: absolute;
      bottom: 20px;
      clear: both; // I think this should solve the problem
    }

Maybe you will need to get rid of position: absolute; 也许您需要摆脱位置:绝对; as well 以及

What you'll want to do is make .rightPanel a flexbox element, and give it display: flex and flex-direction: column . 您需要做的是使.rightPanel成为一个flexbox元素,并为其display: flexflex-direction: column Then simply give all children flex-grow: 1 , apart from .actionBar , which you want to keep fixed to the bottom. 然后,简单地给所有子代flex-grow: 1除了 .actionBar ,您要将其固定在底部。 Note that .rightPanel will need a height for this top work, and this height should also accommodate the offset. 请注意, .rightPanel将需要一个height才能完成此顶部工作,并且该height还应包含偏移量。

This can be seen in the following: 可以在以下内容中看到:

 .rightPanel { position: fixed; right: 0px; top: 20px; display: flex; flex-direction: column; height: calc(100vh - (20px * 2)); } .rightPanel > * { flex-grow: 1; } .actionBar { flex-grow: 0; } 
 <div class="rightPanel"> <header>Header</header> <div class="body">Body</div> <div class="actionBar">Action Bar</div> </div> 

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

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