In this tutorial, you will learn how to make the Materialize media component responsive.
Materialize CSS Media generally refers to media components provided by the Materialize Framework. Materialize is a modern, responsive front-end framework based on material design. It is designed and developed by Google. The framework offers numerous components and utility classes for constructing responsive web applications.
MaterializeCSS Media components include responsive images, videos, and other media elements that adapt to different screen sizes and resolutions. These media components provide help to the developer to create visually appealing and user-friendly interfaces that work well across all the different devices and platforms.
There are the following predefined materialize responsive classes.
To make an image responsive in Materialize.CSS, add the responsive-img
class to the base class of the <img>
element. This class sets the maximum-width
of the image to 100% and the height
to auto. This ensures that the image will scale down proportionally to the width of the viewport while maintaining its aspect ratio. Whenever a Materialize image is placed within a Materialize grid, it will appear visually appealing on all screen sizes.
Source Code
<div class="container">
<img class="responsive-img" src="https://picsum.photos/seed/picsum/200/300" alt="responsive image" />
</div>
Source Code: Output
To create a circular image, simply add the circular
class to the image element. Keep in mind that if the height and width of the image are not equal, the resulting shape will be elliptical rather than perfectly circular. Add an additional .img-responsive
class to make the circular image
responsive.
General Syntax
<img src="../images/materialize-circle.jpg" class="responsive-img circle" alt="Image Circle">
Source Code
<div class="container">
<img src="https://picsum.photos/seed/picsum/200/200" class="responsive-img circle" alt="Image Circle">
</div>
Source Code: Output
Place the embedded video inside the external container and assign the video-container
class to the container. This class makes the embedded video responsive.
Source Code
<div class="row">
<div class="video-container">
<iframe width="854" height="480" src="https://www.youtube.com/embed/cQzien5H2Do"
frameborder="0" allowfullscreen></iframe>
</div>
</div>
Source Code: Output
If you want to make HTML 5 video responsive, then place it inside the <video>
element and add the .responsive-video
class to the base class of the <video>
element.
Source Code
<div class="row center-align">
<video class="responsive-video" controls>
<source src="../images/html5-video.mp4" type="video/mp4" />
</video>
</div>