我正在使用猫头鹰旋转木马2并添加了自定义CSS:
$(document).ready(function() {
$("#owl-demo").owlCarousel({
navigation: true,
pagination: true,
lazyLoad: true
});
});
#owl-demo .owl-item > div img {
display: block;
width: 100%;
height: auto;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
margin-bottom: 4px;
}
#owl-demo .owl-item > div {
padding: 0px 2px
}
#owl-demo .owl-item > div:first-child {
border: 6px solid #e1e1e1;
}
<div id="owl-demo" class="owl-carousel">
<div>
<img class='lazyOwl' data-src="http://placehold.it/200x200/42bdc2/FFFFFF&text=1st Row" alt="" />
</div>
<div>
<img class='lazyOwl' data-src="http://placehold.it/200x200/42bdc2/FFFFFF&text=1st Row" alt="" />
</div>
<div>
<img class='lazyOwl' data-src="http://placehold.it/200x200/42bdc2/FFFFFF&text=1st Row" alt="" />
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="http://owlgraphic.com/owlcarousel/owl-carousel/owl.carousel.min.js"></script>
<link href="http://owlgraphic.com/owlcarousel/owl-carousel/owl.carousel.css" rel="stylesheet" />
<link href="http://owlgraphic.com/owlcarousel/owl-carousel/owl.theme.css" rel="stylesheet" />
这对我有用,但我想使用:last-child
或:first-child
将CSS边框添加到第一个或最后一个div
。在行动中,这不起作用,而是显示所有div
的边框。
我该如何解决这个问题?
DEMO here
答案 0 :(得分:1)
使用:first-child
时,您的逻辑略有错误。使用div
定位.owl-item
内的:first-child
会导致所有div
被选中,因为它们是div
中的第一个.owl-item
。< / p>
您需要做的是使用:first-child
查找.owl-item
的第一个实例,然后定位其中的div
。
需要进行以下更改:
#owl-demo .owl-item > div:first-child
更改为#owl-demo .owl-item:first-child div
$(document).ready(function() {
$("#owl-demo").owlCarousel({
navigation: true,
pagination: true,
lazyLoad: true
});
});
#owl-demo .owl-item > div img {
display: block;
width: 100%;
height: auto;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
margin-bottom: 4px;
}
#owl-demo .owl-item > div {
padding: 0px 2px
}
#owl-demo .owl-item:first-child div {
border: 6px solid #e1e1e1;
}
<div id="owl-demo" class="owl-carousel">
<div>
<img class='lazyOwl' data-src="http://placehold.it/200x200/42bdc2/FFFFFF&text=1st Row" alt="" />
</div>
<div>
<img class='lazyOwl' data-src="http://placehold.it/200x200/42bdc2/FFFFFF&text=1st Row" alt="" />
</div>
<div>
<img class='lazyOwl' data-src="http://placehold.it/200x200/42bdc2/FFFFFF&text=1st Row" alt="" />
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="http://owlgraphic.com/owlcarousel/owl-carousel/owl.carousel.min.js"></script>
<link href="http://owlgraphic.com/owlcarousel/owl-carousel/owl.carousel.css" rel="stylesheet"/>
<link href="http://owlgraphic.com/owlcarousel/owl-carousel/owl.theme.css" rel="stylesheet"/>