this is my demo page我在我的div里面有一个bootstrap列,哪个父类是绝对的,但是我的列不是carousel的中间。怎么做?
你可以看到我的结构
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap 101 Template</title>
<!-- Bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<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="myDiv ">
<div class="container">
<div class="row">
<div class="col-md-6 col-lg-6 col-sm-12 col-xs-12">left column..</div>
<div class="col-md-6 col-lg-6 col-sm-12 col-xs-12">right column..</div>
</div>
</div>
</div>
<div class="item active">
<img src="http://www.aurumhotels.com.tr/resimler/normal/2015-08/FirmaArkaBanner1_4BuFjQUcCp3yALBpDUxLsignature.jpg" alt="...">
</div>
<div class="item">
<img src="http://www.aurumhotels.com.tr/resimler/normal/2015-12/FirmaArkaBanner1_Isrgao2xv47jrJVBsf2Hfirmaarkabanner2.png" alt="...">
</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>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</body>
</html>
CSS
.my-slider{
background:#FFF;
position: absolute;;
top:0;
z-index:1;
}
.item img {
width:100%;
}
答案 0 :(得分:0)
你可以这样做:
.myDiv{
position: absolute;
background: #fff;
z-index:1;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
width: 50%;
}
答案 1 :(得分:0)
尝试此操作并根据需要修复vw(视口宽度)。
.myDiv{
position: absolute;
background:#fff;
z-index:1;
width:50vw;
left:25vw;
}
答案 2 :(得分:0)
您的.myDiv
需要进行一些更改,请添加这些属性:
left: 0;
top: 0;
right: 0;
并将背景移至.myDiv .container
答案 3 :(得分:-1)
由于父级是绝对定位的,因此需要给它的宽度为100%,以使其子容器在容器中居中。我假设我的滑块真的是myDiv:
.myDiv{
background:#FFF;
position: absolute;
top:0;
z-index:1;
width:100%;
}