Is there a way to invert the order of elements in a scrollable container in Google Chrome?

The code snippet provided creates the desired effect, but unfortunately, it only seems to function properly in Firefox and Edge. In Chrome, while the elements are stacked correctly, there is no horizontal scroll bar, making the rightmost items hidden and inaccessible to users.

As demonstrated, the header and footer remain fixed while the my-app element is scrollable. The items on the left display above those on the right, with all items reachable through scrolling.

body {
  margin: 0;
  height: 100vh;
}

my-app {
  display: flex;
  height: 100vh;
  flex-direction: column;
}

header, footer {
  height: 25px;
  background-color: black;
  color:white;
}

main {
  display: flex;
  flex-direction: row-reverse;
  flex-grow: 1;
  justify-content: flex-end;
  margin: 0;
  overflow-x: auto;
  width: 100vw;
}

.card {
  --card-height: 200px;
  --card-width: 250px;

  align-items: center;
  ...
<my-app>
  <header>Header</header>
  <main>
    <div class="card">1</div>
    <div class="card">2</div>
    ...
    <div class="card">15</div>
  </main>
  <footer>Footer</footer>
</my-app>

When changing the CSS properties of main to:

main {
  ...
  flex-direction: row;
  ...
  justify-content: flex-start;
  ...
}

The scrollbar appears, but the items are not stacked correctly (those on the right overlay those on the left).

If adding direction: rtl; to the main style, the layout functions as intended, yet the default scroll position starts at the right side of the screen. While this can be adjusted with JavaScript, it may seem like a hacky solution. Is there a better way to achieve the desired layout that works seamlessly across Chrome, Firefox, and Edge browsers?

Answer №1

By adding an extra wrapper, your issue seems to be resolved:

body {
  margin: 0;
  height: 100vh;
}

my-app {
  display: flex;
  height: 100vh;
  flex-direction: column;
}

header,
footer {
  height: 25px;
  background-color: black;
  color: white;
}

main {
  flex-grow: 1;
  margin: 0;
  overflow-x: auto;
  width: 100vw;
}

.wrapper {
  display: flex;
  flex-direction: row-reverse;
  justify-content: flex-end;
}

.card {
  --card-height: 200px;
  --card-width: 250px;
  align-items: center;
  background: linear-gradient(rgba(179, 156, 95, 1), rgba(150, 117, 24, 1));
  border-radius: 5px;
  box-shadow: 1.5rem 0 2rem #222;
  color: #000;
  display: flex;
  flex-direction: column;
  height: var(--card-height);
  justify-content: center;
  min-width: var(--card-width);
  position: relative;
  text-align: center;
  transition: all .15s ease-in-out;
  transition: margin .3s ease-in-out;
  width: var(--card-width);
}

.card:not(:last-of-type) {
  margin-left: calc(var(--card-width) * -.5);
}

.card:hover:not(:last-of-type) {
  margin-left: 0;
}
<my-app>
  <header>Header</header>
  <main>
    <div class="wrapper">
      <div class="card">1</div>
      <div class="card">2</div>
      <div class="card">3</div>
      <div class="card">4</div>
      <div class="card">5</div>
      <div class="card">6</div>
      <div class="card">7</div>
      <div class="card">8</div>
      <div class="card">9</div>
      <div class="card">10</div>
      <div class="card">11</div>
      <div class="card">12</div>
      <div class="card">13</div>
      <div class="card">14</div>
      <div class="card">15</div>
    </div>
  </main>
  <footer>Footer</footer>
</my-app>

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

Inserting a vertical barrier in the midst of the content

I am struggling to create a vertical divider and align the text properly in the top right corner of my screen. https://i.sstatic.net/UqURE.png Currently, I am facing issues with displaying the divider and positioning the text correctly. <div class="r ...

Ways to expand HTML input fields to fill the whole table cell

Currently working on a calculator project and I'm facing an issue with making a HTML button span the entire cell. I've managed to stretch the button horizontally but struggling to get it to fill the cell completely. Curious as to why setting widt ...

Alter the background color of a table cell in Angular HTML depending on a boolean value

Attempting to use Angular ng-class to set the background color of a table cell. I'm referencing code snippets from these resources: Angular: How to change the color of cell table if condition is true Change HTML table cell background color using ...

Is there a way to obtain metadata for a specific link?

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title><$BlogPageTitle$></title> <meta property="og:title" content=" ...

Vue 3 has a known issue where scoped styles do not get applied correctly within the content of a <slot> element

Utilizing the Oruga and Storybook libraries for creating Vue 3 components. The code in the Vue file looks like this: <template> <o-radio v-bind="$props" v-model="model"> <slot /> </o-radio> </template ...

Utilizing external CSS to style an SVG file within an HTML document

Hello there, I have a collection of SVG files that I need to dynamically modify the fill color of, preferably using CSS. Here is the structure: <div> <svg width="100%" height="100%" viewbox="0 0 64 64" preserveAspectRatio="xMinYMin m ...

Styling rounded buttons with GTK and CSS

In my C++ application, I am attempting to create a rounded button by utilizing an external CSS file. Although I have successfully achieved a round button, there is still a pesky rectangular border that remains and I am struggling to figure out how to remo ...

Hover over an element to trigger the background fading effect on the parent div

I'm looking to create a hover effect on an element within a fullscreen div. When I hover over the element, I want a background image to fade in on the div with the class ".section." While I can easily display the background image, I am unsure of how t ...

Having trouble getting padding to work inside a pre block, even when using a wrapper div?

Snippet of HTML Code: <div class="prewrap"> <pre> stepsize = .01 samplestimes = 30 universex = seq(-1, 1, stepsize) universey = sin(pi * universex) </pre> </div> Sample CSS Styles: #prewrap { background-color: #e3e3e3; pa ...

Adjusting Text Color on Buttons

I am looking for a simple button with clear color and black text, but the default button has white text. I need a way to change the text color. Check out my current app <View style={styles.fastlog}> <Button style={styles.bouton} title= "Con ...

My desire is for every circle to shift consecutively at various intervals using Javascript

I'm looking to draw circles in a sequential manner. I am trying to create an aimbooster game similar to . Instead of drawing all the circles at once, I want each circle to appear after a few seconds. The circles I've created currently do not g ...

Tips for maintaining the height of the outer div consistent with that of the inner div

I am encountering an issue with an inner div that is used for overlay and set to a min-height property. Despite changes in the overlay's height, the height of the outer div remains unaffected. #outer { width: 70px; height: 70px; background-co ...

Is there a advantage to using Angular's component style encapsulation for improved performance?

Recently, I came across the styling methods of Angular 2 which allows you to directly include your styles within the component. If you want to explore more on this topic, check out loading styles. There are two options for style encapsulation in Angular 2 ...

Conceal a column within a table by double-clicking

I'm working on a project with a table, and I'd like to implement a feature where a column hides when double-clicked. I've seen various solutions for hiding columns on Stack Overflow, but I could use some guidance on where to add the ondblcli ...

Optimal approach for creating a CSS button with a dynamic size, gradient background and arrow design

I'm utilizing the Zurb Foundation framework and aiming to create dynamic call-to-action buttons with varying sizes, text, a background gradient, and a right-pointing arrow. There are three potential approaches I've envisioned: Employ an a el ...

Activate the jQuery function multiple times

I am currently working on the menu structure for my website <div class="header"> <ul> <li id="menu__lnk_one"><a href="#">Home</a></li> <li><a href="#">Our Story</a></ ...

Nested flexbox causing Firefox to malfunction in handling overflow-y

I successfully created a layout using CSS3 flexbox that spans 100% width and height. This layout functions properly on IE11, and possibly on IE10 when emulating IE11. Unfortunately, I encountered an issue with Firefox (35.0.1) where the overflow-y propert ...

Angular 6 seems to be having issues loading Bootstrap

I've run into an issue while trying to incorporate Bootstrap into Angular 6. I have already installed Bootstrap using npm install bootstrap and added it to angular.json, but it's still not functioning. Is there something else I should be doing? A ...

The Jquery navigation and image display features are experiencing technical difficulties in Internet Explorer

My website is currently in the development stage and functions well on all browsers except for IE10. Interestingly, both the menu bar and photo gallery, which rely on Jquery, are not functioning properly in IE10. Below is the code snippet: <script ty ...

Is it possible to create a mouse-following effect with lighting using Javascript

Recently, I've been honing my Javascript skills and decided to create a follow-mouse function. After successfully implementing it, I started brainstorming a new concept that I'm unsure is achievable. Is there a way to develop an "orb of vision" ...