2016-04-14 81 views
0

this is my demo page我在我的div里面有引导列,其中父类是绝对的,但是我的列不是传送带的中间..怎么做?如何对齐引导列中的div?

,我添加图片到什么我想要做的 enter image description here

你可以看到我的结构

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

,你可以这样做:

.myDiv{ 
    position: absolute; 
    background: #fff; 
    z-index:1; 
    left: 0; 
    right: 0; 
    margin-left: auto; 
    margin-right: auto; 
    width: 50%; 

}

http://codepen.io/anon/pen/zqWmYB

+0

有趣和great..on codepen它工作得很好,但是,我的桌面与以前的 –

+0

@ani_css一样工作,这在工作中很有用。然而bootstrap的容器失去了1170px的宽度。你是否期望保持容器的宽度为1170px并居中该div? – imvain2

-1

,因为父母是绝对的定位,它将需要被给予宽度10 0%的孩子以集装箱为中心。我要承担起我的滑块是真的myDiv:

.myDiv{ 
     background:#FFF; 
     position: absolute; 
     top:0; 
     z-index:1; 
     width:100%;  
} 
0

试试这个,修复VW(视口宽度)根据您的需要。

.myDiv{ 
     position: absolute; 
     background:#fff; 
     z-index:1; 
     width:50vw; 
     left:25vw; 
} 

http://codepen.io/nikmahes/pen/GZxYpB

+0

谢谢,但项目必须跨浏览器,它必须是工作,即9+ :)) –

0

.myDiv需要一些改变,增加这些属性:

left: 0; 
top: 0; 
right: 0; 

和移动背景.myDiv .container