Cover

Ready Added in 2.0.0

Expand images, videos or iframes to cover their entire container and place your own content on top.

Usage

To have an image cover its parent element, add the .gls-cover-container class to the parent and the gls-cover attribute to the image.

<div class="gls-cover-container">
    <img src="" alt="" gls-cover>
</div>

Note To position content on top of the covering element, use the Position component. To adapt your content for better visibility, add the .gls-light or .gls-dark class from the Inverse component.

  • <div class="gls-cover-container gls-height-medium">
        <img src="https://utahhealthcare.github.io/gloss-docs/images/dark.jpg" alt="" gls-cover>
    </div>
    

Video

To create a video that covers its parent container, add the gls-cover attribute to a video. Wrap a container element around the video and add the .gls-cover-container class to clip the content.

The Cover component inherits all properties from the Video component which means videos are muted and play automatically. The video will pause whenever it’s not visible and resume once it becomes visible again.

<div class="gls-cover-container">
    <video gls-cover></video>
</div>
  • <div class="gls-cover-container gls-height-medium">
        <video autoplay loop muted playsinline gls-cover>
            <source src="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4" type="video/mp4">
            <source src="http://clips.vorwaerts-gmbh.de/VfE.webm" type="video/webm">
            <source src="http://clips.vorwaerts-gmbh.de/VfE.ogv" type="video/ogg">
        </video>
    </div>
    

Iframe

To apply the Cover component to an iframe, you need to add the gls-cover attribute to the iframe. Now add the .gls-cover-container class to a container element around the iframe to clip the content.

<div class="gls-cover-container">
    <iframe src="" gls-cover></iframe>
</div>
  • <div class="gls-cover-container gls-height-medium">
        <iframe src="https://www.youtube-nocookie.com/embed/YE7VzlLtp-4?autoplay=1&amp;controls=0&amp;showinfo=0&amp;rel=0&amp;loop=1&amp;modestbranding=1&amp;wmode=transparent" width="560" height="315" allowfullscreen gls-cover></iframe>
    </div>
    

Responsive height

To add responsive behavior to your cover image, you need to create an invisible <canvas> element and assign width and height values to it, according to the aspect ratio you want the covered area to have. That way it will adapt the responsive behavior of the image.

<div class="gls-cover-container">
    <canvas width="" height=""></canvas>
    <img src="" alt="" gls-cover>
</div>
  • <div class="gls-cover-container">
        <canvas width="400" height="200"></canvas>
        <img src="https://utahhealthcare.github.io/gloss-docs/images/dark.jpg" alt="" gls-cover>
    </div>
    

Viewport height

Adding the gls-height-viewport attribute from the Height component will stretch the height of the parent element to fill the whole viewport.

<div class="gls-cover-container" gls-height-viewport>
    <img src="" alt="" gls-cover>
</div>

Component options

Any of these options can be applied to the component attribute. Separate multiple options with a semicolon. Learn more

Option Value Default Description
automute Boolean true Tries to automute the iframe’s video.
width Number undefined The element’s width.
height Number undefined The element’s height.

JavaScript

Learn more about JavaScript components.

Initialization

Gloss.cover(element, options);