我有一个使用Bootstrap 3的网页。在我的网页中,我有一个横幅,我 想要修复(即坚持)到顶部。在横幅下方,我有我的内容,分为两个主要部分:文本和相关内容。
文本只是一个长文本块。相关内容是一些链接。但是,要将相关内容区分开来,我试图给它一个灰色背景。我希望灰色背景能够覆盖页面的整个高度(减去横幅的高度)。当用户滚动时,我希望灰色背景保持原位,但内容可能会滚动。换句话说,长文本块和相关内容不彼此独立滚动。
出于某种原因,我一直无法弄清楚如何在侧面板上获得灰色背景。高度关闭。我一直在试验Bootply。它具有以下代码:
<div class="container-fluid container-title">
<div class="container text-center text-title">
<div>Welcome</div>
</div>
</div>
<div style="height:100%;">
<div class="row">
<div class="col-md-8">
<div style="padding:24px;">
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."
Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"
1914 translation by H. Rackham
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"
</div>
</div>
<div class="col-md-1"></div>
<div class="col-md-3 sidebar">hello</div>
</div>
</div>
如何让侧边栏填满整个屏幕高度(减去横幅的高度)?
答案 0 :(得分:1)
您可以使用一些JavaScript来获取文档的高度 - 侧边栏的高度。
另外,不要使用带有Bootstrap的空DIV,没有必要。您可以使用偏移类。例如。 col-md-3 col-md-offset-1
$('.sidebar').height(($(document).height() -$('.container-fluid.container-title').height()));
&#13;
/* CSS used here will be applied after bootstrap.css */
.container-title {
padding-left:0;
padding-right:0;
background-color:#fff;
border-bottom:1px solid #2D2D2D;
height:72px;
}
.text-title {
padding-top:14px;
font-size:28px;
font-weight:normal;
text-align:center;
}
.sidebar {
background-color:#EEE;
height:100%;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="container-fluid container-title">
<div class="container text-center text-title">
<div>Welcome</div>
</div>
</div>
<div style="height:100%;">
<div class="row">
<div class="col-xs-8">
<div style="padding:24px;">
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."
Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"
1914 translation by H. Rackham
"But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?"
</div>
</div>
<div class="col-xs-3 sidebar">hello</div>
</div>
</div>
&#13;
答案 1 :(得分:0)
你可以做出正确的位置:固定&#34;并相应地设定高度。由于您需要侧边栏100%高度,侧边栏(容器 - 流体,排等)的任何容器也需要全高。使用calc(..)
减去顶部横幅的高度。您可能还想使用媒体查询来仅修复大屏幕上的侧边栏..
@media (min-width: 992px) {
body {
overflow: hidden;
}
.main>.row {
height:calc(100% - 72px);
}
.sidebar {
background-color:#EEE;
height:100%;
position: fixed;
right:0;
}
}