标题下方的 Bootstrap3 图片,重新缩放图片以适合
Bootstrap3 Image Below Caption, Rescale Image To Fit
我正在使用 HTML 和 JS 创建一个简单的旋转木马。我现在主要是我想要的样子,不幸的是有几个问题:
运行 片段:
1) 我希望标题位于图像下方的 space 中,而不是图像上。我已经根据我的小技能用 CSS 做了我能做的,但想不通。
2) 另外,我希望图片调整大小并居中,以便适合轮播,而不是大部分图片被裁剪掉。
旋转木马伸出
1) 我已经使网站响应,并且容器有 style="text-align:center;text-align: justify;"
。但是,如果您查看下图,在某些情况下,当浏览器 window 最小化时,轮播会突出。我该如何解决这个问题?
.carousel-caption {
position: relative;
left: auto;
top: auto;
bottom: -95px;
}
.carousel-inner {
overflow: visible;
padding-bottom: 95px;
}
#serviceSlider .item {
height: 400px;
}
#slide1{
background:url('https://cdn.pixabay.com/photo/2020/03/31/19/20/dog-4988985_960_720.jpg'); center no-repeat;
}
#slide2{
background:url('https://cdn.pixabay.com/photo/2017/02/20/18/03/cat-2083492_960_720.jpg'); center no-repeat;
}
#slide3{
background:url('https://cdn.pixabay.com/photo/2018/05/09/22/44/piglet-3386356_960_720.jpg'); center no-repeat;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<style>
.carousel-inner>.item>img,
.carousel-inner>.item>a>img {
width: 100%;
margin: auto;
}
</style>
<div class="container" style="text-align:center;text-align: justify;">
<br>
<div id="serviceSlider" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#serviceSlider" data-slide-to="0" class="active"></li>
<li data-target="#serviceSlider" data-slide-to="1"></li>
<li data-target="#serviceSlider" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active" id="slide1">
<div class="carousel-caption">
<h3>Dog</h3>
<p>Cute Corgi.</p>
</div>
</div>
<div class="item" id="slide2">
<div class="carousel-caption">
<h3>Cat</h3>
<p>Cute cat.</p>
</div>
</div>
<div class="item" id="slide3">
<div class="carousel-caption">
<h3>Pigs</h3>
<p>Sleepy pigs.</p>
</div>
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#serviceSlider" 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="#serviceSlider" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
您无需做太多事情,只需对字幕轮播 class 进行一些更改即可。尝试复制和粘贴,看看它是否有效。 css.
中没有其他更改
<div id="carouselExampleCaptions" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="https://cdn.pixabay.com/photo/2020/03/31/19/20/dog-4988985_960_720.jpg" class="d-block w-100" alt="...">
<div class="text-center d-none d-md-block">
<h5>First slide label</h5>
<p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p>
</div>
</div>
<div class="carousel-item">
<img src="https://cdn.pixabay.com/photo/2020/03/31/19/20/dog-4988985_960_720.jpg" class="d-block w-100" alt="...">
<div class="text-center d-none d-md-block">
<h5>Second slide label</h5>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</div>
<div class="carousel-item">
<img src="https://cdn.pixabay.com/photo/2020/03/31/19/20/dog-4988985_960_720.jpg" class="d-block w-100" alt="...">
<div class="text-center d-none d-md-block">
<h5>Third slide label</h5>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleCaptions" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleCaptions" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
我正在使用 HTML 和 JS 创建一个简单的旋转木马。我现在主要是我想要的样子,不幸的是有几个问题:
运行 片段:
1) 我希望标题位于图像下方的 space 中,而不是图像上。我已经根据我的小技能用 CSS 做了我能做的,但想不通。
2) 另外,我希望图片调整大小并居中,以便适合轮播,而不是大部分图片被裁剪掉。
旋转木马伸出
1) 我已经使网站响应,并且容器有 style="text-align:center;text-align: justify;"
。但是,如果您查看下图,在某些情况下,当浏览器 window 最小化时,轮播会突出。我该如何解决这个问题?
.carousel-caption {
position: relative;
left: auto;
top: auto;
bottom: -95px;
}
.carousel-inner {
overflow: visible;
padding-bottom: 95px;
}
#serviceSlider .item {
height: 400px;
}
#slide1{
background:url('https://cdn.pixabay.com/photo/2020/03/31/19/20/dog-4988985_960_720.jpg'); center no-repeat;
}
#slide2{
background:url('https://cdn.pixabay.com/photo/2017/02/20/18/03/cat-2083492_960_720.jpg'); center no-repeat;
}
#slide3{
background:url('https://cdn.pixabay.com/photo/2018/05/09/22/44/piglet-3386356_960_720.jpg'); center no-repeat;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<style>
.carousel-inner>.item>img,
.carousel-inner>.item>a>img {
width: 100%;
margin: auto;
}
</style>
<div class="container" style="text-align:center;text-align: justify;">
<br>
<div id="serviceSlider" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#serviceSlider" data-slide-to="0" class="active"></li>
<li data-target="#serviceSlider" data-slide-to="1"></li>
<li data-target="#serviceSlider" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active" id="slide1">
<div class="carousel-caption">
<h3>Dog</h3>
<p>Cute Corgi.</p>
</div>
</div>
<div class="item" id="slide2">
<div class="carousel-caption">
<h3>Cat</h3>
<p>Cute cat.</p>
</div>
</div>
<div class="item" id="slide3">
<div class="carousel-caption">
<h3>Pigs</h3>
<p>Sleepy pigs.</p>
</div>
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#serviceSlider" 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="#serviceSlider" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
您无需做太多事情,只需对字幕轮播 class 进行一些更改即可。尝试复制和粘贴,看看它是否有效。 css.
中没有其他更改<div id="carouselExampleCaptions" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="https://cdn.pixabay.com/photo/2020/03/31/19/20/dog-4988985_960_720.jpg" class="d-block w-100" alt="...">
<div class="text-center d-none d-md-block">
<h5>First slide label</h5>
<p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p>
</div>
</div>
<div class="carousel-item">
<img src="https://cdn.pixabay.com/photo/2020/03/31/19/20/dog-4988985_960_720.jpg" class="d-block w-100" alt="...">
<div class="text-center d-none d-md-block">
<h5>Second slide label</h5>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</div>
<div class="carousel-item">
<img src="https://cdn.pixabay.com/photo/2020/03/31/19/20/dog-4988985_960_720.jpg" class="d-block w-100" alt="...">
<div class="text-center d-none d-md-block">
<h5>Third slide label</h5>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleCaptions" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleCaptions" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>