Card: Responsive Objects

Responsive Objects

Flexible as a Magical Mirror

Das <object> Element is fantastic for embedding various content into your website, but without the right CSS, it can be as stubborn as an old enchanted mirror, refusing to fit neatly into place!

Fear not, though—with a touch of CSS magic, your <object> becomes not just beautiful but also clever. It adapts gracefully to any screen size, blending seamlessly into your design. Whether on a desktop or a small enchanted viewing box, the right CSS ensures your embedded content stays elegant and poised—almost as if it instinctively knows exactly how much space it needs. No more squabbles, just smooth transitions!

Object with CSS

Token: responsive Objects

An Object

That Adapts

Seamlessly integrate your objects into their surroundings, allowing them to blend perfectly with the design. You can follow the same approach you learned for iframes.

In this example, you use a 16:9 aspect ratio achieved with padding-bottom: 56.25%. The <object> element will then fill the entire container and flexibly adapt to any screen size. You can also enhance your element with additional styles, like borders or shadows, to make it visually appealing and cohesive within your design.
This way, your <object> remains beautifully responsive and fits elegantly into your webpage, no matter the size of your visitor’s device!

HTML
<div class="object-container">
    <object data="file.pdf" type="application/pdf">
    </object>
</div>
CSS
.iframe-container {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%;
    /* For a 16:9 aspect ratio */
    height: 0;
    overflow: hidden;
}

.iframe-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}
HTML
<div class="object-container">
    <object data="assets/media/elixir-of-light.pdf" type="application/pdf">
    </object>
</div>
CSS
.object-container {
    position: relative;
    width: 90%;
    padding-bottom: 56.25%;
    /* For a 16:9 aspect ratio */
    height: 0;
}

.object-container object {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 2px solid #333;
    /* Optional: Border */
    box-shadow:
        0 4px 8px rgba(0, 0, 0, 0.591);
    /* Optional: Shadow */
}
Scroll to Top