我想在大屏幕和桌面屏幕的 Bootstrap 轮播中放置一个内容 DIV
。请参阅下图以了解您的理解。
在手机和标签页中应该是这样的——
我不确定如何使用 bootstrap 3 创建此布局。希望有人可以帮助我。
这是我当前的标记:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<main role="main">
<div id="homepage-feature" class="carousel slide">
<ol class="carousel-indicators">
<li data-target="#homepage-feature" data-slide-to="0" class="active"></li>
<li data-target="#homepage-feature" data-slide-to="1"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active" style="background: url(img/slider/uniform.jpg) no-repeat center center; background-size: cover;">
<div class="container">
<div class="carousel-caption">
<h3>Providing you the Best</h3>
<h1>Cleaning Companies</h1>
<p>in Bahrain with 10% Discount.</p>
</div>
</div>
</div>
<div class="item" style="background: url(img/slider/uniform.jpg) no-repeat center center; background-size: cover;">
<div class="container">
<div class="carousel-caption">
<h1>Example headline.</h1>
<p class="lead">Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
<a class="btn btn-large btn-primary" href="#">Sign up today</a>
</div>
</div>
</div>
</div>
<!-- /.carousel-inner -->
<!-- Controls -->
<a class="left carousel-control" href="#homepage-feature" data-slide="prev">
‹
</a>
<a class="right carousel-control" href="#homepage-feature" data-slide="next">
›
</a>
</div>
<!-- /#homepage-feature.carousel -->
<div style="width: 300px; height: 500px; background: red;"></div>
</main>
最佳答案
演示:https://jsbin.com/lufoli
在每个中断宽度处镜像 .container 的大小,这就是名为“.red
”的父级。将 .red
绝对定位元素居中,方法是使用 left: 50%,然后在每个断点处使用宽度为 1/2 的负边距。然后在该父级中添加表单/div,并在最小宽度处刷新它。
CSS
.slide-wrapper {
position: relative
}
.red {
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
.red-content {
width: 100%;
height: 300px;
background: red;
color: #fff;
}
@media (min-width: 768px) {
.carousel-caption {
text-align: left;
padding-right: 300px;
}
.red {
width: 750px;
position: absolute;
left: 50%;
top: 0;
bottom: 0;
padding: 20px 0;
margin-left: -375px;
}
.red-content {
width: 300px;
float: right;
height: 100%;
background: red;
color: #fff;
margin-right:15px; /* width of .container gutter */
}
}
@media (min-width: 992px) {
.red {
width: 970px;
margin-left: -485px;
}
}
@media (min-width: 1200px) {
.red {
width: 1170px;
margin-left: -585px;
}
}
/* MISC */
#homepage-feature .item {
overflow: hidden;
height: 400px;
background-color: transparent;
background-size: cover;
}
#homepage-feature > .carousel-control {
width: 30px;
font-size: 40px;
color: #fff;
text-shadow: none;
filter: none;
opacity: 1;
}
#homepage-feature > .carousel-control span {
position: absolute;
top: 50%;
margin-top: -30px;
width: 100%;
text-align: center;
display: block;
}
HTML
<div class="slide-wrapper">
<div id="homepage-feature" class="carousel slide">
<ol class="carousel-indicators">
<li data-target="#homepage-feature" data-slide-to="0" class="active"></li>
<li data-target="#homepage-feature" data-slide-to="1"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active" style="background-image:url(http://lorempixel.com/1500/600/abstract)">
<div class="carousel-caption">
<h1>Changes to the Grid</h1>
<p>Bootstrap 3 still features a 12-column grid, but many of the CSS class names have completely changed.</p>
<p><a class="btn btn-large btn-primary" href="#">Learn more</a>
</p>
</div>
</div>
<div class="item" style="background-image:url(http://placehold.it/1500x600)">
<div class="carousel-caption">
<h1>Percentage-based sizing</h1>
<p>With "mobile-first" there is now only one percentage-based grid.</p>
<p><a class="btn btn-large btn-primary" href="#">Browse gallery</a>
</p>
</div>
</div>
</div>
<!-- /.carousel-inner -->
<!-- Controls -->
<a class="left carousel-control" href="#homepage-feature" data-slide="prev">
<span class="fa fa-angle-left"></span>
</a>
<a class="right carousel-control" href="#homepage-feature" data-slide="next">
<span class="fa fa-angle-right"></span>
</a>
</div>
<!-- /#homepage-feature.carousel -->
<div class="red">
<div class="red-content">
Content goes here.
</div>
</div>
</div>
<!-- /.container.slide-wrapper -->
关于html - 如何将 Content DIV 放在 bootstrap carousel 上并使其响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28722010/