[英]How can I get css and js only for this carousel?
I have been trying to get only css for this carousel with custom bootstrap but it is aboslutely not working for me, it completely changes the site我一直试图为这个带有自定义引导程序的旋转木马只获取 css 但它绝对不适合我,它完全改变了网站
This is the html for the carousel:这是用于旋转木马的 html:
<div class="container text-center my-3">
<div id="recipeCarousel" class="carousel slide w-100" data-ride="carousel">
<div class="carousel-inner w-100" role="listbox">
<div class="carousel-item row no-gutters active">
<div class="col-3 float-left"><img class="img-fluid" src="http://placehold.it/350x280/222/fff?text=1"></div>
<div class="col-3 float-left"><img class="img-fluid" src="http://placehold.it/350x280/444?text=2"></div>
<div class="col-3 float-left"><img class="img-fluid" src="http://placehold.it/350x280/888?text=3"></div>
<div class="col-3 float-left"><img class="img-fluid" src="http://placehold.it/350x280/111/fff?text=4"></div>
</div>
<div class="carousel-item row no-gutters">
<div class="col-3 float-left"><img class="img-fluid" src="http://placehold.it/350x280?text=5"></div>
<div class="col-3 float-left"><img class="img-fluid" src="http://placehold.it/350x280/555?text=6"></div>
<div class="col-3 float-left"><img class="img-fluid" src="http://placehold.it/350x280/333/fff?text=7"></div>
<div class="col-3 float-left"><img class="img-fluid" src="http://placehold.it/350x280/bbb?text=8"></div>
</div>
</div>
<a class="carousel-control-prev" href="#recipeCarousel" 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="#recipeCarousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
If anyone could help me get just the css and js from bootstrap I would greatly appreciate it !!如果有人可以帮助我从引导程序中获得 css 和 js,我将不胜感激!
In order to limit the scope of your CSS you have to create a unique selector.为了限制 CSS 的 scope,您必须创建一个唯一的选择器。 In your code you use
id="recipeCarousel"
and since id
should be unique on the page, while class
selectors allow multiple elements of the same class, all your CSS for this carousel should start with id.在您的代码中,您使用
id="recipeCarousel"
并且由于id
在页面上应该是唯一的,而class
选择器允许相同 class 的多个元素,您所有的 CSS 都应该以这个 carousel 开头。
This code will select only elements with carousel-inner
class within recipeCarousel
element.此代码将 select 仅在 recipeCarousel 元素中具有
carousel-inner
recipeCarousel
的元素。
#recipeCarousel carousel-inner {
background: blue;
}
You can have both ID and Classes on your elements.您可以在元素上同时拥有 ID 和类。 So if you want to select the wrapper as well, you can change it to
因此,如果您也想 select 包装器,您可以将其更改为
<div id="myCarousel" class="container text-center my-3">
...
</div>
and start selecting from there.并从那里开始选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.