How to Make Materializecss Slider Resize Height According to Devices

0

I would like to make the Materialize Css slider that has a default height of 400px in all responsive sizes.

I would like this height to have its height changed as per the device.

I'm using the following CSS code

.slider .slides {
    margin: 0;
    height: 400px;
}

.slider .slides li img {
    height: 100%;
    width: 100%;
    background-position: center;
    background-size: 100% auto;
    background-repeat: no-repeat;
}

See picture below that illustrates the problem.

    
asked by anonymous 23.09.2018 / 15:53

1 answer

1

Media Querys serve to determine a style for a particular situation (eg example, specific screen size, orientation, etc.)

For screen sizes, you usually use these breakpoints:

/* Extra small devices (phones, 600px and down) */
@media only screen and (max-width: 600px) {...}

/* Small devices (portrait tablets and large phones, 600px and up) */
@media only screen and (min-width: 600px) {...} 

/* Medium devices (landscape tablets, 768px and up) */
@media only screen and (min-width: 768px) {...} 

/* Large devices (laptops/desktops, 992px and up) */
@media only screen and (min-width: 992px) {...} 

/* Extra large devices (large laptops and desktops, 1200px and up) */
@media only screen and (min-width: 1200px) {...}

Materialize uses breakpoints, see the Creating Responsive Layouts section

An example usage:

document.addEventListener('DOMContentLoaded', function() {
  var elems = document.querySelectorAll('.carousel');
  var instances = M.Carousel.init(elems, {});
});
img {
  height: 100%;
}

/* Extra small devices (phones, 600px and down) */
@media only screen and (max-width: 600px) {
  .carousel-item {
    height: 100px !important;
  }
}

/* Small devices (portrait tablets and large phones, 600px and up) */
@media only screen and (min-width: 600px) {
  .carousel-item {
    height: 200px !important;
  }
}

/* Medium devices (landscape tablets, 768px and up) */
@media only screen and (min-width: 768px) {
  .carousel-item {
    height: 300px !important;
  }
}

/* Large devices (laptops/desktops, 992px and up) */
@media only screen and (min-width: 992px) {
  .carousel-item {
    height: 400px !important;
  }
}

/* Extra large devices (large laptops and desktops, 1200px and up) */
@media only screen and (min-width: 1200px) {
  .carousel-item {
    height: 500px !important;
  }
}
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">

<div class="carousel">
  <a class="carousel-item" href="#one!"><img src="https://lorempixel.com/250/250/nature/1"></a><aclass="carousel-item" href="#two!"><img src="https://lorempixel.com/250/250/nature/2"></a><aclass="carousel-item" href="#three!"><img src="https://lorempixel.com/250/250/nature/3"></a><aclass="carousel-item" href="#four!"><img src="https://lorempixel.com/250/250/nature/4"></a><aclass="carousel-item" href="#five!"><img src="https://lorempixel.com/250/250/nature/5"></a></div><!--CompiledandminifiedJavaScript--><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
    
24.09.2018 / 18:11