Struggle with creating a responsive Strava Iframe (CSS/HTML)

UPDATE:
My ongoing attempts to make the iframe container responsive have been focused on adjusting its size based on the intrinsic ratio of the iframe. Unfortunately, this approach has not fully worked as some elements of the iframe remain fixed in place. I am struggling to achieve a truly responsive Strava Iframe and have shared my current attempts in a Codepen Collection.

I recently implemented a shortcode to embed Strava iframes on my Hugo site using the academic theme. While the iframes display properly and are responsive on desktop browsers, they do not adapt well on mobile devices. The issue can be observed on this webpage or my GitHub repo. Any help in resolving this would be greatly appreciated.

I have experimented with various CSS tweaks recommended on the Hugo forum and other online sources.

Current Shortcode:

{{ if and (.Get "id") (.Get "hash") }}
<div class="responsive-object">
<iframe height='405' width='590' frameborder="0" allowtransparency='true' scrolling='no' src="https://www.strava.com/activities/{{ .Get "id" }}/embed/{{ .Get "hash" }}"></iframe>
</div>
{{ end }}

Current CSS:

.responsive-object iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.responsive-object {
  position: relative;
  padding-bottom: 67.5%;
  height: 0;
  margin: 10px 0;
  overflow: hidden;
}
Despite my efforts to create a responsive iframe container, it still does not display correctly on mobile devices. I am at a loss for what steps to take next and suspect that I may have overlooked something crucial.

Answer №1

Are you including the

<meta name="viewport" content="width=device-width, initial-scale=1.0">

In your HTML <Head> section?

If so, I will update my post with the solution :)

UPDATE

A fantastic resource I came across for creating responsive iframes is How To Make Responsive Iframes - It's Easy!.

Here are the key points to keep in mind:

  1. Avoid setting attributes such as width and height directly on the iframe opening tag.

  2. Enclose the iframe within a div container, set height: 0; and then use padding-bottom: nn%; to establish the container's height based on the width-height ratio as a percentage.

  3. Apply inline styles to the div using -webkit-overflow-scrolling: touch and overflow: auto to manage scrolling on mobile devices effectively as these properties can be unreliable when specified in CSS.

This code snippet has worked well for me:

// Include this HTML within an embed block (not a code block)

<div class="iframe-container iframe-container-for-wxh-500x350" style="-webkit-overflow-scrolling: touch; overflow: auto;">

 <iframe src="http://www.targetWebsiteURL.com"> <p style="font-size: 110%;"><em><strong>IFRAME: </strong> There is iframe content being displayed here but your browser version does not support iframes.</em> Please update your browser to its most recent version and try again.</p> </iframe>

 </div>

// And utilize this CSS styling

.iframe-container { position: relative; margin: 5px; height: 0; overflow: hidden; }

.iframe-container-for-wxh-500x350 {
padding: 25px 25px 70% 25px; /* padding-bottom = h/w as a % */
}

.iframe-container iframe {
position: absolute;
top: 0;
left: 0;
margin: 0;
padding: 0;
width: 100%;
height: 100%;
border: 1px inset #7a8b8b;
/* Place the following styles (important for handling overflow and scrolling) inside the div container around the iframe
as they may not behave consistently in CSS
-webkit-overflow-scrolling: touch;
overflow: auto; */

} Create a distinct class to define the padding-bottom property, making it easier to handle multiple iframes with varying width-height ratios by simply applying different percentages in each designated class.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Running a CSS keyframes animation can be achieved by removing the class associated with it

Is there a way to reverse the CSS animation when a class is removed? I'm trying to achieve this on my simple example here: https://codepen.io/MichaelRydl/pen/MWPvxex - How can I make the animation play in reverse when clicking the button that removes ...

Display the name of the link on the console

I am working on an HTML list that contains some links: <ul> <li><a href="#" name="link1">link1</a></li> <li><a href="#" name="link2">link2</a></li> <li><a href="#" name="link3">link3& ...

Creating a dynamic full-width background image that adjusts its height according to the content: a step-by-step guide

Currently, I'm attempting to apply a background image to a webpage that spans 100% width in order to adjust to the viewport size. The method I am using involves placing an image directly after the body tag with the subsequent styling: img#background ...

Is there a way to align an element to the right of a centered element?

I am trying to center two inputs ("email" and "password") horizontally on the page. However, I also want to add another item to the right of them while keeping the inputs centered. <div style={{ display: "flex", justifyContent: "center" }}> < ...

Remembering position in JSP using Java Beans

In my "Web Engineering" assignment, I am tasked with developing a Web Application game using JSP, Servlets, and Java Beans. The game mechanics are already in place with the Servlet controlling the algorithms, JSP handling the Model/View, and Beans managing ...

Tips for attaching an image to an email

Can anyone assist me with an HTML form that sends emails using PHP with image attachments? I have tried various codes, but none of them seem to work properly. The message gets sent with all the texts and even the image name, but the actual image is missing ...

What is the actual purpose of the <header> and <footer> elements in web design?

Why are headers and footers important on a webpage? Considering that they appear in the order they are written on the page, as shown here, what distinguishes a header from a footer? <article> <footer>This is a footer</footer> &l ...

What is the best way to modify a variable in a nested element using ng-click in the parent element?

Review this code snippet: <section class="page-section about-us" scroll-bookmark="about-us" ng-click="activeSection=true" ng-init="activeSection=false"> <div class="page-content sub-content active-section">{{activeSection}} < ...

Guide on implementing recursion in JavaScript by accepting parameters as inputs

Could you please help me identify the error in this code snippet? I'm having trouble implementing recursion without parameters. The code only seems to work when I remove the parameters. Code Snippet let number = document.getElementById("inputN").val ...

Cannot utilize Map within each loop

Below is the less code snippet: @threshold:{ a:50; b:200; }; @themes:{ a:red; b:blue; }; .mymixin(@name,@color,@thrshld){ //do-something } each(@themes,{ .mymixin(@key,@value,@threshold[@key]); }); Upon executing the code, an error message ...

Troubleshooting compatibility problems between jQuery UI Sortable and a responsive Bootstrap 5 page

Has anyone had experience using the jQuery UI Sortable widget on a Bootstrap 5 responsive page? My page consists of <div class="col-lg-6"> elements, displaying two per row. Although the sorting functionality works, I've encountered t ...

Having trouble getting the Twitter Bootstrap navbar to display properly on mobile and iPad browsers

Is there a way to make the navigation bar float on mobile browsers when using the "navbar" and "navbar-fixed-top" classes? I've tried this on various devices like iPad (Safari, Chrome), Android (Firefox), and Windows Phone (IE), but it doesn't se ...

Guide to adding a new Vue-Grid-Item with a button

Currently, I am working on a software project for the Research department at my university, specifically focusing on an Atomic Layer Deposition system. The main goal of this program is to allow users to create and customize their own 'recipe' for ...

Ways to display a checked or unchecked checkbox in react depending on a boolean value obtained from an API

Is there a way to display a checked or unchecked checkbox in react jsx depending on a boolean value retrieved from an api? ...

What is the best way to integrate my custom JavaScript code into my WordPress theme, specifically Understrap?

I am looking to enhance my website with a sticky navbar positioned directly under the header, and I want it to stick to the top of the page as users scroll down. Additionally, I want the header to disappear smoothly as the user scrolls towards the navbar. ...

Troubleshooting a CSS problem with iPad browsers

I have a specific issue related to CSS on iPad. I am working with a set of sublinks and have defined the styles in CSS as follows: #leftNav .searchBySub {...} #leftNav a.searchBySub:hover {...} #leftNav .searchBySubClicked {...} In my JavaScr ...

Building Valid HTML Strings with Qt4.2's QTextEdit

My goal is to create HTML content to display correctly in a QTextEdit using Qt 4.2 on RHEL 5.3. Although I am not a professional web developer, I believe the HTML generated by my algorithm is valid. 319:14:27:22: <font color="rgb(255,0,0)" bgcolor="r ...

Can you tell me what is creating the space between the elements in this form?

For an example, take a look at this link: I am puzzled by the gap between the form-group and the button, as well as between the different form-groups. When using Bootstrap 4 with flexbox activated, all my elements (inputs and buttons) collapse without any ...

Tips for placing an image in the bottom right corner of a frame

My goal on the Roman Numismatics page is to place the yellow 'bid' button at the lower right corner of each frame. Current code <p><a href="<?= $product->page_url() ?>"><img border="0" alt="Bid&qu ...

Is Consistency Possible with CSS Transition Direction?

Take a look at this example: https://codepen.io/jon424/pen/XWzGNLe In the provided code snippet, there is a button that can toggle the visibility of an image. When clicked, the image disappears from bottom to top and reappears when clicked again. The use ...