回复:http : //twitter.github.io/bootstrap/components.html#alerts
我想在我的页面顶部显示这些警报。但是,每当我这样做时,它都会将其下方的内容向下推。我不想要那个。我希望它只是重叠(意思是,它出现在顶部,但顶部的内容不会被下推)。
我可能在给定时间显示多个这些警报。对于那些,我认为我需要将它们堆叠在每个警报之上(否则,用户将无法阅读它们)。
我该怎么做呢?首选仅 CSS 解决方案。如果绝对需要,对非 TB、jQuery 解决方案开放。
回复:http : //twitter.github.io/bootstrap/components.html#alerts
我想在我的页面顶部显示这些警报。但是,每当我这样做时,它都会将其下方的内容向下推。我不想要那个。我希望它只是重叠(意思是,它出现在顶部,但顶部的内容不会被下推)。
我可能在给定时间显示多个这些警报。对于那些,我认为我需要将它们堆叠在每个警报之上(否则,用户将无法阅读它们)。
我该怎么做呢?首选仅 CSS 解决方案。如果绝对需要,对非 TB、jQuery 解决方案开放。
您可以将警报放在绝对定位的容器中,将它们从流中弹出:
.alerts {
position: absolute;
top: 30px;
left: 20px;
right: 20px;
}
<div class="main">
<h1>Heading</h1>
<p>
Some content here...
</p>
</div>
<!-- the order of elements is insignificant (you can swap the main
container and the alerts container and have the same result) -->
<div class="alerts">
<div class="alert">alerting...</div>
<div class="alert">alerting once more...</div>
</div>
这可以使用 Bootstrap 声明性组件(使用 CSS 挂钩)进行演示,但也可以使用 Bootstrap 命令式 API(通过 JavaScript 调用)。
这是一个关于 plunker 的现场演示,说明了这一点。