Bootstrap 轮播让我的页脚显示在中间
Bootstrap carousel makes my footer display on the middle
如果我尝试在具有 Bootstrap 轮播的页面上显示页脚,则页脚不会位于页面底部。
如果我删除旋转木马,页脚会转到底部。
我的基本页脚是:
.footer {
position: absolute;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 60px;
background-color: #f5f5f5;
}
在此处查看演示:http://jsfiddle.net/2d4wn1aw/1/
有人知道为什么吗?
谢谢。
尝试删除所有 <br>
并在 .footer
上将 position:
切换为 relative;
粘性页脚基本上是一个 div
,它用 min-height: 100%
和负数 margin-bottom
包裹所有内容(与页脚高度相同,但负数),然后在其中另一个 div
wrapper
将 push
空白 space 与 footer
相同的 height
,为它(footer
)留出空间,这将在外面包装纸。
首先你必须用 position:relative;
添加包装器然后删除那些 <br>
这是示例:http://jsfiddle.net/Lgs1L673/1/
你只需要 删除 position: absolute
在 .footer
或至少 将其更改为 position: relative
.footer
中的 position: absolute
属性 导致页脚从元素流中移除。通过删除此属性,您的页脚将尊重其在 DOM 中的位置(您将其放在 HTML 的末尾,因此它将是页面上的最后一块内容)。
position:relative
设置在 carousel 上,footer 有 position:absolute
这意味着 footer 与 carousel 有关并且 bottom:0
你是说 footer 将直接在 carousel 之后,从 footer 中删除 position absolute 将使它是免费的,您可以改用 position:relative
,
/* for testing only */
.item img {width: 100%; height: auto}
.carousel,
.item {
height: 100%;
}
.carousel-inner {
height: 100%;
}
.carousel-indicators li {
padding:5px;
background-color: #999;
}
.carousel-indicators .active {
background-color: #444;
}
.fill {
width: 100%;
height: 100%;
background-position: center;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
}
.footer {
position: relative;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 60px;
background-color: #f5f5f5;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="http://placehold.it/450x350" alt="Slide 1">
<div class="carousel-caption">
Caption Slide 1
</div>
</div>
<div class="item">
<img src="http://placehold.it/450x350" alt="Slide 2">
<div class="carousel-caption">
Caption Slide 2
</div>
</div>
<div class="item">
<img src="http://placehold.it/450x350" alt="Slide 3">
<div class="carousel-caption">
Caption Slide 3
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<footer class="footer">Blablabla
</footer>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
如果我尝试在具有 Bootstrap 轮播的页面上显示页脚,则页脚不会位于页面底部。
如果我删除旋转木马,页脚会转到底部。
我的基本页脚是:
.footer {
position: absolute;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 60px;
background-color: #f5f5f5;
}
在此处查看演示:http://jsfiddle.net/2d4wn1aw/1/
有人知道为什么吗?
谢谢。
尝试删除所有 <br>
并在 .footer
position:
切换为 relative;
粘性页脚基本上是一个 div
,它用 min-height: 100%
和负数 margin-bottom
包裹所有内容(与页脚高度相同,但负数),然后在其中另一个 div
wrapper
将 push
空白 space 与 footer
相同的 height
,为它(footer
)留出空间,这将在外面包装纸。
首先你必须用 position:relative;
添加包装器然后删除那些 <br>
这是示例:http://jsfiddle.net/Lgs1L673/1/
你只需要 删除 position: absolute
在 .footer
或至少 将其更改为 position: relative
.footer
中的 position: absolute
属性 导致页脚从元素流中移除。通过删除此属性,您的页脚将尊重其在 DOM 中的位置(您将其放在 HTML 的末尾,因此它将是页面上的最后一块内容)。
position:relative
设置在 carousel 上,footer 有 position:absolute
这意味着 footer 与 carousel 有关并且 bottom:0
你是说 footer 将直接在 carousel 之后,从 footer 中删除 position absolute 将使它是免费的,您可以改用 position:relative
,
/* for testing only */
.item img {width: 100%; height: auto}
.carousel,
.item {
height: 100%;
}
.carousel-inner {
height: 100%;
}
.carousel-indicators li {
padding:5px;
background-color: #999;
}
.carousel-indicators .active {
background-color: #444;
}
.fill {
width: 100%;
height: 100%;
background-position: center;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
}
.footer {
position: relative;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 60px;
background-color: #f5f5f5;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="http://placehold.it/450x350" alt="Slide 1">
<div class="carousel-caption">
Caption Slide 1
</div>
</div>
<div class="item">
<img src="http://placehold.it/450x350" alt="Slide 2">
<div class="carousel-caption">
Caption Slide 2
</div>
</div>
<div class="item">
<img src="http://placehold.it/450x350" alt="Slide 3">
<div class="carousel-caption">
Caption Slide 3
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<footer class="footer">Blablabla
</footer>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>