简体   繁体   English

bootstrap css,如何在容器内制作全宽div

[英]bootstrap css, how to make full width div inside container

I want to make this kind of layout with bootstrap framework: 我想用bootstrap框架进行这种布局:

    |   | menu       x |    |
    -------------------------
    ** **  full width  ** **
    -------------------------
    |   | site content |    |
    |   |              |    |
    |   |              |    |
    |   |              |    |
    |   |              |    |
    |   |              |    |
    |   |              |    |
    |   |              |    |
    |   |              |    |
    -------------------------

I want a "container-fluid" div holding a "container" menu and it works fine, my problem is that I need to add a "full width" div just under the menu and I have no idea how to do this. 我想要一个“容器流体”div拿着一个“容器”菜单,它工作正常,我的问题是我需要在菜单下添加一个“全宽”div,我不知道如何做到这一点。 Site content should have the "container" class while "full width" div "container-fluid", but I know that it's not possible to nest such classes. 网站内容应该有“容器”类,而“全宽”div“容器 - 流体”,但我知道嵌套这样的类是不可能的。

how can I fix this with css keeping in mind that "menu" is fixed at top and "full width" div must scroll normally? 我如何用css解决这个问题,记住“菜单”固定在顶部,“全宽”div必须正常滚动? I think I cannot use absolute positioning. 我想我不能用绝对定位。 I hope it's clear, otherwise I'll try to improve the question. 我希望它很清楚,否则我会尝试改进这个问题。

I would do three different containers, each one holds header, full width and site content accordingly 我会做三个不同的容器,每个容器相应地保存标题,全宽和网站内容

<div class="container"></div> <!-- header here -->
<div></div> <!-- full width here -->
<div class="container"></div> <!-- site content here -->

You can use positioning for this, and by using three different 'panels', you can position them wherever you wish on the page (and make them responsive, as well). 可以使用定位,通过使用三个不同的“面板”,您可以将它们放在页面上的任何位置(并使它们响应)。 For example: 例如:

 .html, body { margin: 0; padding: 0; } .container { width: 100%; min-height: 100vh; background: rgba(0, 0, 0, 0.2); position: relative; } .leftpanel,.rightpanel { width: 20%; min-height: 100vh; position: absolute; top: 0; left: 0; background: lightgray; } .rightpanel { left:auto; right: 0; } .content { width: 60%; min-height: 100vh; position: absolute; top: 0; left: 20%; background: gray; } 
 <div class="container"> <div class="leftpanel">Left Side</div> <div class="content">Body container</div> <div class="rightpanel">Right Container</div> </div> 

It's pretty easy to do, but you can't put them all in 1 container class: 它很容易做到,但你不能将它们全部放在1个容器类中:

header.container
   ... menu
div.container-fluid
   ... banner
div.container
   ... content

if you "fix" your menu to the top, just add a padding to your body for at least the height of the menu. 如果您将菜单“固定”到顶部,只需在您的身体上添加一个填充至少高度的菜单。

如果是全宽,那么只需将填充/边距设置为0(我知道这不是最佳做法)

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

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