Bootstrap 轮播 - 使标题响应 window 高度
Bootstrap Carousel - Make caption responsive to window height
我在我的页面上实现了 Bootstrap 旋转木马,但出于某种原因,我无法根据网络浏览器的大小将标题文本设置为 re-position。
这是我的 HTML 代码:
<!-- =======================CAROUSEL=========================== -->
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="item active">
<img class="first-slide" src="img/main-banner.png" alt="First slide">
<div class="container">
<div class="carousel-caption">
<h1>Democratizing the Internet of Things!</h1>
<p><a class="btn btn-lg btn-primary" href="./index.php?d=splash" role="button">Try Splash</a></p>
</div>
</div>
</div>
<div class="item">
<img class="second-slide" src="img/banner-2.png" alt="Second slide">
<div class="container">
<div class="carousel-caption">
<h1>Another Heading!</h1>
</div>
</div>
</div>
<a class="left carousel-control" href="#myCarousel" 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="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
我正在使用 Bootstrap CDN:
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
这些是我对轮播所做的所有 CSS 更改:
.carousel-caption {
position: relative !important;
width: 550px;
top: 210px;
left: 380px !important;
z-index: 600;
max-height:177px;
}
.carousel-caption h1 {
font-family: sans-serif !important;
font-size: 44px !important;
font-weight: 700 !important;
line-height:36px !important;
color: #444 !important;
margin: 0px !important;
padding: 0px !important;
text-shadow: 0px 0px 4px #fff !important;
text-align: left !important;
}
.carousel-caption p {
margin-top: 11px !important;
font-size:18px !important;
line-height:21px !important;
color:#333 !important;
padding-bottom: 11px !important;
margin-bottom: 11px !important;
text-shadow: 0px 0px 4px #fff !important;
text-align: left !important;
}
.carousel-control.left, .carousel-control.right {
background-image: none !important;
}
.carousel-indicators {
left: 405px !important;
}
这是轮播全屏显示的内容:
下面是我开始更改网络浏览器大小时发生的情况:
我尝试过所有不同类型的职位,但我终究无法弄清楚自己做错了什么。感谢您的帮助!
我使用
做轮播响应
@media(最大宽度:767px){
具体尺码款式
}
并为该尺寸添加我的样式,我使用不同尺寸的树来让所有屏幕尺寸对齐。
为了在中心垂直对齐标题,我使用了 CSS 函数 translateY
或 属性 transform
。
我还希望将标题直接放在左侧轮播控件的旁边。
我还删除了默认添加的额外底部 space bootstrap CSS。
.carousel-caption {
width: 550px;
left: 15%;
top: 50% !important;
transform: translateY(-50%);
text-align: left;
bottom: initial;
}
现在无论屏幕大小如何,标题都能正确显示:
我在我的页面上实现了 Bootstrap 旋转木马,但出于某种原因,我无法根据网络浏览器的大小将标题文本设置为 re-position。
这是我的 HTML 代码:
<!-- =======================CAROUSEL=========================== -->
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="item active">
<img class="first-slide" src="img/main-banner.png" alt="First slide">
<div class="container">
<div class="carousel-caption">
<h1>Democratizing the Internet of Things!</h1>
<p><a class="btn btn-lg btn-primary" href="./index.php?d=splash" role="button">Try Splash</a></p>
</div>
</div>
</div>
<div class="item">
<img class="second-slide" src="img/banner-2.png" alt="Second slide">
<div class="container">
<div class="carousel-caption">
<h1>Another Heading!</h1>
</div>
</div>
</div>
<a class="left carousel-control" href="#myCarousel" 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="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
我正在使用 Bootstrap CDN:
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
这些是我对轮播所做的所有 CSS 更改:
.carousel-caption {
position: relative !important;
width: 550px;
top: 210px;
left: 380px !important;
z-index: 600;
max-height:177px;
}
.carousel-caption h1 {
font-family: sans-serif !important;
font-size: 44px !important;
font-weight: 700 !important;
line-height:36px !important;
color: #444 !important;
margin: 0px !important;
padding: 0px !important;
text-shadow: 0px 0px 4px #fff !important;
text-align: left !important;
}
.carousel-caption p {
margin-top: 11px !important;
font-size:18px !important;
line-height:21px !important;
color:#333 !important;
padding-bottom: 11px !important;
margin-bottom: 11px !important;
text-shadow: 0px 0px 4px #fff !important;
text-align: left !important;
}
.carousel-control.left, .carousel-control.right {
background-image: none !important;
}
.carousel-indicators {
left: 405px !important;
}
这是轮播全屏显示的内容:
下面是我开始更改网络浏览器大小时发生的情况:
我尝试过所有不同类型的职位,但我终究无法弄清楚自己做错了什么。感谢您的帮助!
我使用
做轮播响应@media(最大宽度:767px){ 具体尺码款式 }
并为该尺寸添加我的样式,我使用不同尺寸的树来让所有屏幕尺寸对齐。
为了在中心垂直对齐标题,我使用了 CSS 函数 translateY
或 属性 transform
。
我还希望将标题直接放在左侧轮播控件的旁边。
我还删除了默认添加的额外底部 space bootstrap CSS。
.carousel-caption {
width: 550px;
left: 15%;
top: 50% !important;
transform: translateY(-50%);
text-align: left;
bottom: initial;
}
现在无论屏幕大小如何,标题都能正确显示: