gpt4 book ai didi

html - 左侧边栏与内容区域高度相同,页脚位于浏览器窗口底部

转载 作者:太空宇宙 更新时间:2023-11-03 22:30:20 24 4
gpt4 key购买 nike

我在使用 Bootstrap 3.3.7 创建布局时遇到了一些困难。

我设置了一个 fiddle 来展示我得到的东西:https://jsfiddle.net/b8ukxb41/5/

我似乎无法解决 3 个问题:

  1. 我希望左侧导航菜单(用红色边框标出)与内容区域(用蓝色边框标出)高度相同。

  2. 无论内容区域内有多少内容,页脚都应始终位于浏览器窗口的“底部”。我想要粘性页脚 - 如果浏览器中出现滚动条,则页脚应始终位于浏览器窗口的底部,而不是粘性。

  3. 如果内容区中有大量内容,右侧应该有一个滚动条。但是,左侧导航菜单应保持在固定位置。

我能描述的最接近 Gmail,你可以向下滚动右侧的邮件列表,但左侧的文件夹导航保持在固定位置 - 并且左侧栏一直向下到浏览器窗口的底部。

我尝试了以下方法来解决问题,但这些解决方案均无效:

  1. 使用 display: flex;在带有绿色边框的容器上,即 <div class="container-fluid" style="border:1px solid green; display: flex;"> .这似乎没有做任何事情。我基于 How can I make Bootstrap columns all the same height? 中的信息

  2. 我试过为页脚使用以下 CSS:

     footer {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    }

问题在于,有时页脚会出现在带有红色边框的导航菜单“内部”。如果您向右滚动到窗口底部,它只会出现在浏览器窗口的底部。

  1. 我不知道如何做到这一点,尽管我想要的效果与这里显示的一样:https://codepen.io/sass-munch/pen/YerOLG

下图总结了我试图实现的总体目标:红色边框导航应该与蓝色边框内容区域的高度相同。标题应该是固定的。页脚应始终出现在浏览器窗口的底部 - 无论蓝色内容区域中有多少内容:

enter image description here

最佳答案

根据给定的 HTML

没有 flexbox
  • 设置页脚的高度,例如50 像素
  • 主要内容、侧边栏和右侧的.content:

    高度:calc(100vh - 100px)(50px 导航栏高度和 50px 页脚高度)。

  • 右侧设置.content overflow-y: auto.

例子

main,
main aside,
main .content {
height: calc(100vh - 100px);
}

main {
margin-top: 50px;
}

main aside,
main .content {
padding: 15px 0;
}

main aside {
background: red;
}

main .content {
overflow-y: auto;
background: blue;
}

.footer {
height: 50px;
line-height: 50px;
background: #F8F8F8;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<div class="navbar navbar-fixed-top navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Project name</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div>
<!-- /.nav-collapse -->
</div>
<!-- /.container -->
</div>
<!-- /.navbar -->

<main>
<div class="container-fluid">
<div class="row">
<aside class="hidden-xs col-sm-3">
<ul>
<li>List 1</li>
<li>List 2</li>
<li>List 3</li>
<li>List 4</li>
<li>List 5</li>
</ul>
</aside>
<div class="content col-sm-9">
<div class="jumbotron">
<a href="#" class="visible-xs" data-toggle="offcanvas"><i class="fa fa-lg fa-reorder"></i></a>
<h1>test</h1>
<p>This is an example to show the potential of an offcanvas layout pattern in Bootstrap. Try some responsive-range viewport sizes to see it in action.</p>
</div>
<div class="col-xs-12">
<h2>Heading</h2>
<p>Bootstrap is a front-end framework that uses CSS and JavaScript to facilitate responsive Web design. Bootply is a playground for Bootstrap that enables developers and designers to test, prototype and create mockups using Bootstrap friendly HTML,
CSS and Javascript.</p>
<p><a class="btn btn-default" href="#">View details »</a></p>
</div>
<div class="col-xs-12">
<h2>Heading</h2>
<p>Bootstrap is a front-end framework that uses CSS and JavaScript to facilitate responsive Web design. Bootply is a playground for Bootstrap that enables developers and designers to test, prototype and create mockups using Bootstrap friendly HTML,
CSS and Javascript.</p>
<p><a class="btn btn-default" href="#">View details »</a></p>
</div>
<div class="col-xs-12">
<h2>Heading</h2>
<p>Bootstrap is a front-end framework that uses CSS and JavaScript to facilitate responsive Web design. Bootply is a playground for Bootstrap that enables developers and designers to test, prototype and create mockups using Bootstrap friendly HTML,
CSS and Javascript.</p>
<p><a class="btn btn-default" href="#">View details »</a></p>
</div>
<div class="col-xs-12">
<h2>Heading</h2>
<p>Bootstrap is a front-end framework that uses CSS and JavaScript to facilitate responsive Web design. Bootply is a playground for Bootstrap that enables developers and designers to test, prototype and create mockups using Bootstrap friendly HTML,
CSS and Javascript.</p>
<p><a class="btn btn-default" href="#">View details »</a></p>
</div>
</div>
</div>
</div>
</main>

<footer class="footer">
<div class="container-fluid">
Footer
</div>
</footer>

关于html - 左侧边栏与内容区域高度相同,页脚位于浏览器窗口底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48811035/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com