我正在尝试使用CSS使Materialise滑块响应,但它无法正常工作。当我使用Firefox的自适应视图测试我的代码时,我得到的滑块图像响应时灰色背景远大于滑块图像的高度(如下所示)。
.slider .slides li img {
background-size: 100% auto;;
background-repeat: no-repeat;
}
<div class="row">
<div class="slider " >
<ul class="slides ">
<li>
<img class="responsive-img" id="img" src="{{ asset('font/images/IMG_61.jpg') }}">
</li>
<li>
<img class="responsive-img" id="img" src="{{ asset('font/images/IMG_53.jpg') }}">
</li>
<li>
<img class="responsive-img" id="img" src="{{ asset('font/images/IMG_2.jpg') }}">
</li>
</ul>
</div>
</div>
答案 0 :(得分:2)
试试这个,适合我
.slider .slides {
background-color: transparent;
margin: 0;
height: 400px;
}
.slider .slides li img {
height: 100%;
width: 100%;
background-position: center;
background-size:100% auto;
background-repeat: no-repeat;
}
答案 1 :(得分:0)
这是对我有用的解决方案: 手动为中小型设备将滑块的高度分配为250px,对于大型设备(宽度大于600px的设备),将滑块的高度手动分配为600px
@media only screen and (max-width: 600px) {
.slides {
height: 250px !important;
}
.slider {
height: 250px !important;
}
}
@media only screen and (min-width: 600px) {
.slides {
height: 600px !important;
}
.slider {
height: 600px !important;
}
}
答案 2 :(得分:0)
您实际上已经添加了:
.fullscreen
滑动条,这可以正常工作,如文档中所示。耐心地读书,这就是全部:)
https://materializecss.com/fullscreen-slider-demo.html
Codepen显示标记和初始化:
https://codepen.io/doughballs/pen/YzXqdPO
<div class="slider fullscreen">
<ul class="slides">
<li class="active" style="opacity: 1; transform: translateX(0px) translateY(0px);">
<img src="data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" style="background-image: url("https://images.unsplash.com/photo-1464817739973-0128fe77aaa1?dpr=1&auto=compress,format&fit=crop&w=1199&h=799&q=80&cs=tinysrgb&crop=");"> <!-- random image -->
<div class="caption center-align" style="opacity: 1; transform: translateX(0px) translateY(0px);">
<h3>This is our big Tagline!</h3>
<h5 class="light grey-text text-lighten-3">Here's our small slogan.</h5>
</div>
</li>
<li class="" style="opacity: 0; transform: translateX(0px) translateY(0px);">
<img src="data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" style="background-image: url("https://ununsplash.imgix.net/photo-1414849424631-8b18529a81ca?q=75&fm=jpg&s=0e993004a2f3704e8f2ad5469315ccb7");"> <!-- random image -->
<div class="caption left-align" style="opacity: 0; transform: translateX(-100px);">
<h3>Left Aligned Caption</h3>
<h5 class="light grey-text text-lighten-3">Here's our small slogan.</h5>
</div>
</li>
<li class="" style="opacity: 0; transform: translateX(0px) translateY(0px);">
<img src="data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" style="background-image: url("https://ununsplash.imgix.net/uploads/1413259835094dcdeb9d3/6e609595?q=75&fm=jpg&s=6a4fc66161293fc4a43a6ca6f073d1c5");"> <!-- random image -->
<div class="caption right-align" style="opacity: 0; transform: translateX(100px);">
<h3>Right Aligned Caption</h3>
<h5 class="light grey-text text-lighten-3">Here's our small slogan.</h5>
</div>
</li>
</ul>
<ul class="indicators"><li class="indicator-item active"></li><li class="indicator-item"></li><li class="indicator-item"></li></ul></div>