Unmoving placement within a flexible layout for horizontally scrolling pages

Currently in the process of constructing my portfolio site, I have a decent grasp of HTML and CSS. I am exploring a new design concept for a horizontal scrolling page but have hit a roadblock. My dilemma lies in achieving a fixed heading while allowing the content to scroll horizontally.

Initially, I tried using a fixed position for the header. However, if the screen size changes causing the heading to span multiple lines, it does not push the content below it away as intended. How can I ensure that a fixed div pushes other content aside? Should I reconsider using fixed positioning, or is there another way to address this issue?

Visual representation of text on a single line

Illustration of the problem where the fixed heading overlaps with the content instead of pushing it away

.sub-page {
  padding-left: 40px;
  padding-top: 40px;
  flex-direction: column;
}

.sub-page h2 {
  margin-bottom: 16px;
  position: fixed;
}

.scrolling-wrapper {
  display: flex;
  width: 100%;
  height: auto;
  flex-wrap: nowrap;
  -webkit-overflow-scrolling: touch;
  
}
<div class="container">

    <div class="page sub-page">
        <h2>Selected works</h2>

        <div class="scrolling-wrapper">

            <div class="list">

                <a class="list-item"><h3>Card</h3></a>
                <a class="list-item"><h3>Card</h3></a>
                <a class="list-item"><h3>Card</h3></a>
                <a class="list-item"><h3>Card</h3></a>
                <a class="list-item"><h3>Card</h3></a>
                <a class="list-item"><h3>Card</h3></a>
                <a class="list-item"><h3>Card</h3></a>
                <a class="list-item"><h3>Card</h3></a>
                <a class="list-item"><h3>Card</h3></a>
                <a class="list-item"><h3>Card</h3></a>
                <a class="list-item"><h3>Card</h3></a>

            </div>
        </div>
    </div>

Incorporated JS code for horizontal scrolling: https://codepen.io/nachitz/pen/LXmGzN

It seems like the scrolling effect may be affecting the entire page?

Provided access to my live site to offer real-time insight: cdn.thevoyageofdesign.com/selected-works.html

Answer №1

If you replace position: fixed with position: sticky, it will shift other content away from your header.

.sub-page {
  padding-left: 40px;
  padding-top: 40px;
  flex-direction: column;
}

.sub-page h2 {
  margin-bottom: 16px;
  position: sticky;
  top: 0;
  background-color: #fff;
}

.scrolling-wrapper {
  display: flex;
  width: 100%;
  height: auto;
  flex-wrap: nowrap;
  -webkit-overflow-scrolling: touch;
  
}
<div class="container">

        <div class="page sub-page">
            <h2>Selected works</h2>
    
            <div class="scrolling-wrapper">
    
                <div class="list">
                    <a class="list-item"><h3>Card</h3></a>
                    <a class="list-item"><h3>Card</h3></a>
                    <a class="list-item"><h3>Card</h3></a>
                    <a class="list-item"><h3>Card</h3></a>
                    <a class="list-item"><h3>Card</h3></a>
                    <a class="list-item"><h3>Card</h3></a>
                    <a class="list-item"><h3>Card</h3></a>
                    <a class="list-item"><h3>Card</h3></a>
                    <a class="list-item"><h3>Card</h3></a>
                    <a class="list-item"><h3>Card</h3></a>
                    <a class="list-item"><h3>Card</h3></a>
    
                </div>
            </div>
        </div>
    </div>

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

Utilizing Media Queries in a browser operating within a virtualized environment

Recently, I encountered a peculiar issue on my website where a tab positioned fixed on the right-hand side disappears when the viewport width becomes less than X due to media queries. While this functions smoothly in most modern browsers starting from ie6, ...

What is the default method for printing in landscape orientation?

How can I print in default landscape mode? Even when I specify landscape mode, the printing comes out in portrait mode. I have tried the following code but it is not working: @media print{@page {size: landscape}} I need help resolving this issue. I wa ...

Slide-out left menu using HTML and CSS

Currently, I am in the process of constructing a website that requires a menu to gracefully slide from the left side of the screen (with a width of 0px) to the right side (expanding to a width of 250px), all with the help of jQuery animations. Here is wha ...

My HTML grid table is not being properly rendered by the JSON data

I'm currently facing a challenge with rendering my HTML grid table in Angular using JSON data retrieved from a MySQL database. I would greatly appreciate any assistance or guidance on how to solve this issue. View the output of the Angular code here ...

Adjust the Bootstrap flex settings to display only 3 cards instead of the default 4 cards - HTML

We currently have a bootstrap setup that displays 4 horizontal scroll cards by default. However, we are looking to only show 3 cards in view and allow the 4th card to be viewed by scrolling. Code On mobile view, the code is still displaying 4 tiles even ...

Separating text for tooltips from the element itself

I'm looking to enhance my website by adding tooltip descriptions to elements based on their CSS classes. While tooltips are usually added using the element's title attribute, I have numerous elements with the same lengthy description and want to ...

determine the distance between two elements in motion

I am attempting to calculate the distance between two dynamically moving HTML elements. Currently, I have them moving on hover, but the result does not change as they move. What could be causing this issue? Below is my code: var lFirst = $("#x").offset ...

Modify the button background image, text, and shape simultaneously when hovered

Can a button's background image or text change, along with its shape, when hovered over using CSS, JS, or both? For example, if I have a button displaying a checkmark symbol ✓ and I want it to transform from a circle shape to a rectangle shape, and ...

MUI Typography - Text turns white when hovered over

I've created a customized component that turns green on hover. Here's the code for it: const ProjectAdd= styled.div` background-color: white; list-style-type: none; list-style: none; height: 100%; width: 10%; height: 100%; border-ra ...

Avoid duplicate submissions while still enforcing mandatory fields

Let's start with a basic form that only asks for an email address: <form action="NextPage.php" method="post"> <input type="email" name="contact[email]" required id="frmEmailA" autocomplete="email"> <button type="submit">Subm ...

Extracting phone numbers from the 'Call' button in Google's local search results on mobile devices: A step-by-step guide

As I was conducting a search using a mobile User Agent for "chiropractors+New York+NY," Google presented me with a page that resembled the following: https://i.sstatic.net/o5ewW.png I am interested in programmatically extracting the phone number linked t ...

Arrange various numbers in a single row to be in line with

I'm utilizing bootstrap in an attempt to design the layout depicted below: https://i.sstatic.net/0w06U.png Here is a simplified version of my code: .curr { font-size: 12px; font-weight: 700; letter-spacing: .5px; } .price { -webkit-tap-h ...

Execute AngularJS code when a button is clickeddoubleValue

I am in the process of developing a dynamic page where users can add anywhere from 1 to n products effortlessly. Although I have been exploring AngularJS for several months, I find myself facing some challenges when conceptualizing this scenario. The HTM ...

Customizing checkbox appearance without including a label

After following a tutorial on how to style checkboxes found here, I was able to create a custom styled checkbox. However, I noticed that when I removed the label from the checkbox, it disappeared and was no longer visible. Is there a way to display the c ...

How can I restrict the Bootstrap dropdown menu to only open downwards?

I'm encountering a minor issue with my Bootstrap Select Box on the following Website As you scroll up and down the page, you'll notice that the dropdown opens in both directions, which is causing disruption. I'm not sure if this is a bug ...

Utilizing a database for storing information from a website, such as usernames, passwords, responses, comments, and more

Can you link a website to an Access database? I currently use an Access database in Visual Basic and I want one database for all my applications. Is this possible? If so, does anyone have any code or examples to share? ps: This is for a school project, so ...

Having trouble getting the jQuery validate function to work properly with a select element

I have successfully implemented a validate function for my input fields : $.tools.validator.fn("#password", function(input, value) { return value!='Password' ? true : { en: "Please complete this mandatory field" }; }); $("# ...

Using a capital "S" in the stylesheet reference within the "rel" attribute

After conducting a thorough investigation, I have come across something that has left me pondering and unable to grasp the reasoning behind it. It involves capitalizing the S in stylesheet for the rel attribute value. What is the difference between: < ...

Styling web pages with CSS, arranging circles in a

I am looking to create circular divs similar to the one in my code below. However, I want them to be stacked behind each other. Specifically, I would like a blue circle (that expands) positioned behind the current red circle but aligned center. The red cir ...

Can the start and stop times of the typed.js plugin be controlled for typing text?

The typed.js jQuery plugin creates the illusion of text being automatically typed on screen by a robot. Despite researching the resources related to this plugin, I have not come across any information on how to control the starting and stopping of the typi ...