Sup*_*etz 20 html css twitter-bootstrap
我有一个自举旋转木马,我正在尝试为旋转木马创建一个标题,该标题始终垂直居中并略微向左定位.我有水平定位的CSS ...但是当我尝试垂直定位时,标题不会保持不变.如何保持.carousel-caption始终垂直居中并略微向左?
HTML:
<!-- start JumboCarousel -->
<div id="jumboCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators hidden-xs">
<li data-target="#jumboCarousel" data-slide-to="0" class="active"></li>
<li data-target="#jumboCarousel" data-slide-to="1"></li>
<li data-target="#jumboCarousel" data-slide-to="2"></li>
<li data-target="#jumboCarousel" data-slide-to="3"></li>
</ol><!-- end carousel-indicators -->
<!-- Wrapper for Slides -->
<div class="carousel-inner" role="listbox">
<div class="item active" id="slide1">
<a href="#"><img src="http://placehold.it/1920x720&text=Slide+1" alt="Slide 1"></a>
<div class="carousel-caption">
<h1>Check Out this Moose</h1>
<p class="lead">This text is super engaging and makes you want to click the button.</p>
<a href="#" class="btn btn-lg btn-primary">Learn More</a>
</div><!-- end carousel-caption -->
</div><!-- end slide1 -->
<div class="item" id="slide2">
<img src="http://placehold.it/1920x720&text=Slide+2" alt="Slide 2">
<div class="carousel-caption">
<h1>#Slide Title</h1>
<p class="lead">This text is super engaging and makes you want to click the button.</p>
<a href="#" class="btn btn-lg btn-primary">Learn More</a>
</div><!-- end carousel-caption -->
</div><!-- end slide2 -->
<div class="item" id="slide3">
<img src="http://placehold.it/1920x720&text=Slide+3" alt="Slide 3">
<div class="carousel-caption">
<h1>#Slide Title</h1>
<p class="lead">This text is super engaging and makes you want to click the button.</p>
<a href="#" class="btn btn-lg btn-primary">Learn More</a>
</div><!-- end carousel-caption -->
</div><!-- end slide3 -->
<div class="item" id="slide4">
<img src="http://placehold.it/1920x720&text=Slide+4" alt="Slide 4">
<div class="carousel-caption">
<h1>#Slide Title</h1>
<p class="lead">This text is super engaging and makes you want to click the button.</p>
<button type="button" href="#" class="btn btn-lg btn-primary">Learn More</button>
</div><!-- end carousel-caption -->
</div><!-- end slide4 -->
</div><!-- end carousel-inner -->
</div><!-- end jumboCarousel -->
Run Code Online (Sandbox Code Playgroud)
CSS:
#jumboCarousel {
margin-top: 70px;
min-height: 300px;
min-width: 100%;
}
#jumboCarousel img {
min-height: 300px;
min-width: 100%;
}
#jumboCarousel > .carousel-indicators > li {
border-radius: 0px;
min-width: 25px;
background-color: #9d9d9d;
border: 1px solid black;
margin-right: 10px;;
margin-left: 10px;;
}
#jumboCarousel > .carousel-indicators > .active {
background-color: orange;
}
#jumboCarousel .carousel-caption {
color: black;
right: 58%;
text-align: center;
max-width: 500px;
left: auto;
top: auto;
}
Run Code Online (Sandbox Code Playgroud)
我所做的任何事情都是为了给标题提供一个垂直对齐,最终随着屏幕大小减小,标题被推出旋转木马的顶部..感谢您的帮助.
Bootply:http://www.bootply.com/aWK6oVRWVo
Seb*_*lia 59
您可以使用translateYCSS属性的功能transform垂直对齐元素.浏览器支持相当不错,包括IE9.因此,只需将以下内容添加到.carousel-captionCSS中即可.
top: 50%;
transform: translateY(-50%);
Run Code Online (Sandbox Code Playgroud)
现在你需要摆脱额外的bottom空间,由默认的bootstrap CSS添加.将以下内容添加到.carousel-captionCSS中.
bottom: initial;
Run Code Online (Sandbox Code Playgroud)
最后但并非最不重要的是给出父元素,在这种情况下.item,使用以下CSS来防止模糊元素放置在半个像素上.
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
transform-style: preserve-3d;
Run Code Online (Sandbox Code Playgroud)