Issues with fixed elements and responsive design solutions

Apologies for the lackluster title, feel free to suggest a better one for this question.

I am looking to revamp the layout of my page for mobile devices. The current desktop version is shown below:

https://i.sstatic.net/r84aS.png

My goal is to achieve something similar to the following:

https://i.sstatic.net/N2ySv.png

The text should stick and adjust itself using JavaScript while scrolling through each step. I have a .text-container element with a specific height matching the drawings' entire height. The .text element is the sticky element.

Here's how my HTML is structured:

<article>
    <div class="figure">
        <div class="step" id="step-1"></div>
        <div class="step" id="step-2"></div>
        <div class="step" id="step-2-5"></div>
        <div class="step" id="step-3"></div>
        <div class="step" id="step-4"></div>
    </div>
    <div class="text-container">
        <div class="text">
            <h1>
                Step <span>1</span>
            </h1>
            <div class="bold">Alice’s phone broadcasts a random message every few minutes</div>
            <p>
                In order to maintain user privacy, the message is sent over Bluetooth and does not use location for proximity detection.
                <br>
                This message is called a Proximity Identifier or EphID. These identifiers are unique and change often.
            </p>
        </div>
    </div>
</article>

Below is the CSS I am using to adjust the layout (written in SCSS):

@media (max-width: 960px) {
    article {
        .text-container {
            .text {
                top: 50vh;
                left: 0;
                width: 100vw;
                height: 50vh;
                background: grey;
            }
        }
    }
}

However, I am encountering an issue, resulting in this layout:

https://i.sstatic.net/y3ryt.png

It appears that there is an issue with the width and positioning of the .text element.

Per the comments, here is a CodePen (without the images, but the functionality remains the same)

Answer №1

After realizing the mistake in my question, it turned out to be a simple oversight on my part with the max-width property causing layout issues.

For anyone facing a similar problem, here is the code snippet that I modified:

@media (max-width: 960px) {
    article {
        .text-container {
            position: absolute;
            top: 100vh;
            left: 0;
            .text {
                position: -webkit-sticky;
                position: sticky;
                top: 50vh;
                left: 0;
                width: 100vw;
                max-width: 100vw;
                height: 50vh;
                background: grey;
            }
        }
    }
}

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

Using JQuery to Identify the Clicked Div Container

Currently working on a JQuery script to determine which specific div box was clicked, but running into some issues. I understand that there are other approaches to achieve this by directly invoking functions upon clicking a div box, but I want to first ide ...

I created a news platform using Next.js server-side rendering, but I'm having trouble with the export const metadata = { title: "TEST" } not functioning as intended

After building my News Website using Next.js with Server Side Rendering, I encountered an issue with setting the page title. Despite using export const metadata = { title: "TEST" }, the title remained unchanged. The metadata object appears to be ...

Leverage the geocode callback function results from Google Maps in NodeJS to render a map on the AngularJS 2 component template

Hey there, I'm currently utilizing the Google Maps Node.js client web API and want to showcase a map on my HTML views using AngularJS 2. I have a server export that sends an object to my AngularJS2 client service const googleMapsClient = require(&ap ...

Having an excessive number of select2 elements (more than 50) on a single screen with identical dropdown values can significantly slow down the page load time

Our screen features a dynamic table where users can add new rows. Each row includes a select2 element, and the table could potentially grow to 50 or more rows. With up to 1000 options in the select2 dropdown, this has been causing slow page loading times. ...

When a user clicks anywhere on the website, the active and focused class will be automatically removed

I'm currently working with Bootstrap tabs on my website. I have three tabs, and when a user clicks on one, the active and focus classes are added to indicate which tab is selected. However, I've encountered an issue where clicking anywhere else ...

Adjusting the visible options in ngOptions causes a disruption in the selected value of the dropdown menu

I have successfully implemented a feature that allows users to convert temperature values displayed in a drop-down menu to either Celsius or Fahrenheit. For this functionality, I am using a select input with ng-options as shown below: <select ng-model ...

Is there a way to use jQuery to efficiently refresh all values within a table?

Whenever I click the "Update All" button, I want all the CHANTIERS values in each line of the list of SALARIES to be checked and updated according to the value selected in the dropdown list. For example, if I choose the value 1 in the dropdown list and cli ...

Tips for aligning 2 divs in the same position?

I am working on a slider feature that includes both videos and pictures. I need to ensure that the videos are hidden when the device width exceeds 600px. Here is the HTML code snippet: <video class="player__video" width="506" height="506" muted preloa ...

Is there a method to make changes to files on a deployed Angular application without the need to rebuild?

After deploying my Angular application on a production environment using the command npm run build --prod --base -href, I now need to make changes to some static HTML and TypeScript files. However, since the app is already bundled and deployed, I'm un ...

Embed SQL parameter into HTML code

Every 24 hours, I have a SQL job that sends an email containing data extracted from my database tables. I store the data in : DECLARE @ReportContentBuilder table(LineSequence int identity, Line varchar(2000)) Here's how it's done : INSERT IN ...

Ensure that the headers of the table are in perfect alignment with the

Is there a way to create a table with fixed row headers so that column headings stay in place while scrolling? I've managed to achieve this, but now the table headers are not aligned properly with the rows below. I've also created a helpful jsfid ...

Tips for selectively applying CSS to a single HTML file

I'm currently working on a website utilizing AngularJS and Plangular to develop a unique Soundcloud Player. This is how I incorporate my template: <body> <div id="container"> <div id="header" ng-controller="HeaderCtrl"><div ...

Leverage the power of effekt in your AngularJS development

Can anyone demonstrate how to implement animation effects with AngularJS? Has someone created an example using Effeckt.css? ...

The CSS style of the Div element is not being displayed properly when embedded with JavaScript

Currently, I am working on a simple page for practice purposes. The main issue I am facing is with a div element that has a red border and a blue background. Inside the div, there is a script tag calling an external JavaScript file. Surprisingly, the JavaS ...

Chrome not displaying fonts properly

Having a font issue in Chrome where specifying "Myriad Pro", Tahoma, Arial results in weird symbols. Works fine in FF, IE, and Safari. Using font-family: Tahoma, Arial; works for all browsers including Chrome. How can Myriad Pro be achieved for IE, FF, a ...

CSS Stylelint rule to detect the 'missing selector' issue

My current process involves using stylelint to identify any CSS errors before building and deploying our site. However, a recent commit includes code that fails the CSS parser/minifier but passes stylelint validation. .example-class , /*.example-class-two ...

Scrape dynamic web data with JSOUP

Having trouble grabbing the price? I cannot seem to get any output for the price and its weight. I've attempted different methods, but nothing is working Document doc = Jsoup.connect("https://www.jakmall.com/tokocamzone/mi-travel-charger-20a-output- ...

Is there a way to compel the browser or JavaScript to delete/disregard a cached file?

I've encountered an issue with my Javascript program that extracts data from a text file and displays it in a table. The problem arises when I update the text file - the changes don't reflect on the table because the browser is caching the file. ...

Is it possible to enable clicking on buttons positioned behind a div without affecting the buttons inside the div?

I am facing a challenge with my webpage where I am using an iFrame to load a dynamic header. The particular situation involves integrating a Shopify page into our larger site, which typically utilizes an Ektron widget to load headers on all other pages. Du ...

Scroll through iTunes on an iPhone using Jquery for a sleek and interactive effect

Would it be possible to create a scrolling effect similar to what the iPhone has in iTunes when browsing through songs? The letter sticking at the top of the screen and being moved by the next one or being replaced. ...