【发布时间】:2017-03-10 15:36:37
【问题描述】:
有一个居中且响应迅速的引导程序container,其中包含内容。我想在容器旁边推一个 div(右侧,与container 相同的top 位置)而不影响居中的容器。
问题是,当我将 float: left 添加到容器并将 float: right 添加到外部 div 时,容器不再居中。只有float: right到外层div才会把div推到右边,但是之后怎么办呢?
我认为带有固定width 的position: absolute 是没有选择的,因为响应式container 将使用不同的视口改变其width。
是否有机会仅使用 HTML 和 CSS 而不使用 JavaScript 来解决此问题?
.main-content {
border: 1px solid red;
}
.outer {
border: 1px solid red;
background: yellow;
text-align: center;
float: right;
width: 70px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<div class="container main-content">
<div class="row">
<div class="col-md-6">
Here ist the content... Here is the content... Here is the content... Here ist the content... Here is the content... Here is the content... Here ist the content... Here is the content... Here is the content... Here ist the content... Here is the content...
</div>
<div class="col-md-6">
Here ist the content... Here is the content... Here is the content... Here ist the content... Here is the content... Here is the content... Here ist the content... Here is the content... Here is the content... Here ist the content... Here is the content...
</div>
</div>
</div>
<div class="outer">
Outer
</div>
【问题讨论】:
标签: html css layout twitter-bootstrap-3