CSS that adjusts to screen size for horizontal scrolling

I'm attempting to implement a horizontal scroll on a webpage so that vertical scrolling will result in horizontal movement. I came across some CSS-based code on CodePen that accomplishes this, but unfortunately it's not responsive.

Is there a way to modify this code to make the page responsive? I've included the code snippet below.

#container {
  margin-top: -15px;
}

#container .box {
  width: 100vw;
  height: 100vh;
  display: inline-block;
  position: relative;
}

#container .box>div {
  width: 100%;
  height: 100%;
  font-size: 96px;
  color: #FFF;
  position: absolute;
  top: 5%;
  left: 2.6%;
  margin: -50px 0 0 -50px;
  line-height: .7;
  font-weight: bold;
}

#container {
  overflow-y: scroll;
  overflow-x: hidden;
  transform: rotate(270deg) translateX(-100%);
  transform-origin: top left;
  background-color: #999;
  position: absolute;
  width: 100vh;
  height: 100vw;
}

#container2 {
  transform: rotate(90deg) translateY(-100vh);
  transform-origin: top left;
  white-space: nowrap;
  font-size: 0;
}

.one {
  background-color: #45CCFF;
}

.two {
  background-color: #49E83E;
}

.three {
  background-color: #EDDE05;
}

.four {
  background-color: #E84B30;
}
<div id="container">
  <div id="container2">

    <div class="box one">
      <div class="full">
        <img class="desktop" src="public/images/lookbook/4.jpg" alt="Header" />
      </div>
    </div>


    <div class="box two">
      <div>2</div>
    </div>


    <div class="box three">
      <div>3</div>
    </div>


    <div class="box four">
      <div>Last</div>
    </div>


  </div>
</div>

If you have any suggestions, please share them with me!

Answer №1

I made the effort to eliminate all those unsightly white spaces and scroll bars, as well as implementing what you requested: Codepen

body,
html {
    height: 100%;
    width: 100%;
    margin: 0;
}

#container {
    width: calc(100vh + 17px);
    height: 100vw;
    margin-top: -17px;
    margin-right: 100px;
    overflow-y: scroll;
    overflow-x: hidden;
    transform: rotate(270deg) translateX(-100%);
    transform-origin: top left;
    background-color: #999;
    position: absolute;
}

#container2 {
    transform: rotate(90deg) translateY(-100vh);
    transform-origin: top left;
    white-space: nowrap;
    font-size: 0;
}

 #container .box {
    width: 100vw;
    height: 100vh;
    display: inline-block;
    position: relative;
} 

 #container .box > div {
    font-size: 96px;
    color: #FFF;
    position: absolute;
    top: 0;
    left: 0;
    margin: 0;
    line-height: 0.9;
    font-weight: bold;
}

.full {
    height: 100%;
    width: 100%;
    position: relative;
}

.desktop {
    width: 100%;
    height: 100%;
    display: block;
    position: absolute;
    background-size: cover;
}

.one {background-color: #45CCFF;}
.two {background-color: #49E83E;}
.three {background-color: #EDDE05;}
.four {background-color: #E84B30;}

Answer №2

If you're looking for the code, try using the image as a background instead of inserting it directly into the div. This way, the image will cover the entire div while remaining responsive to different screen sizes.

body,
html {
    height: 100%;
    width: 100%;
    margin: 0;
}

#container .box {
  width: 100vw;
  height: 100vh;
  display: inline-block;
  position: relative;
  background-size: cover;
}

#container .box>div {
  width: 100%;
  height: 100%;
  font-size: 96px;
  color: #FFF;
  position: absolute;
  top: 5%;
  margin: 20px 0px 0px;
  line-height: .7;
  font-weight: bold;
}

#container {
  overflow-y: scroll;
  overflow-x: hidden;
  transform: rotate(270deg) translateX(-100%);
  transform-origin: top left;
  background-color: #999;
  position: absolute;
  width: 100vh;
  height: 100vw;
}

#container2 {
  transform: rotate(90deg) translateY(-100vh);
  transform-origin: top left;
  white-space: nowrap;
  font-size: 0;
}

.one {
  background-color: #45CCFF;
  background-image: url(https://images.pexels.com/photos/1022454/pexels-photo-1022454.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260);

}

.two {
  background-color: #49E83E;
  background-image: url(https://images.pexels.com/photos/1023949/pexels-photo-1023949.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260);
}

.three {
  background-color: #EDDE05;
  background-image: url(https://images.pexels.com/photos/963071/pexels-photo-963071.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260);
}

.four {
  background-color: #E84B30;
  background-image: url(https://images.pexels.com/photos/1022928/pexels-photo-1022928.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260);
}
<div id="container">
  <div id="container2">
    <div class="box one">
      <div class="full">
        <div>1</div>
      </div>
    </div>
    <div class="box two">
      <div>2</div>
    </div>
    <div class="box three">
      <div>3</div>
    </div>
    <div class="box four">
      <div>Last</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

Harnessing the power of lazysizes with WebP

I've been working on optimizing our site through the Google Lighthouse audit, and it's clear that images are a major focus. Right now, my main goal is to address the issue of 'Deter offscreen images' highlighted in the audit. To tackle ...

Ways to refresh a webxr session while clearing all models from the scene

Whenever the webxr session restarts, I notice that two instances of previous objects appear on the screen. I want the screen to be clear when the session restarts. Currently, I am using the following code: for( var i = scene.children.length - 1; i >= 0 ...

Manipulate text within a text area using jQuery

Good afternoon. How can I use JavaScript to update the text in a textarea input? I currently have some content in my textarea that includes a PublisherImprintName tag, and I want to remove it using jQuery. <PublisherInfo> <PublisherName>A ...

Increasing the size of the entire page can be achieved using the three.js dom element

I am currently working on creating a 3D viewer using three.js. My goal is to have the viewer take up the full height of the screen while also leaving space for a side panel. The vertical layout is functioning properly, but once I add the render's dom ...

React Error - The function 'deleteNinja' has not been declared and is undefined

I'm encountering an issue in Ninja.js where I am trying to delete state data by the Id passed as a prop. The error message I'm receiving is: Failed to compile src\Ninjas.js Line 11:41: 'deleteNinja' is not defined no-undef I&a ...

The hover effect and image opacity adjustment seem to be malfunctioning in my HTML/CSS code

Currently, I am in the midst of a web project and my goal is to implement a hover effect on the first card containing an image. The desired outcome is for the card to move upwards upon hovering, allowing the image to become fully visible with an opacity se ...

How to Retrieve Upload Progress via HTTP Request in PHP

Is there a way to monitor the progress of file uploads by accessing the HTTP request in PHP? If so, how can this be achieved when uploading files into a MySQL database? require('../connect_db.php'); //Collect all necessary data $name = $dbc-> ...

What is the best way to show the response data in an input text field within an HTML form?

I'm new to working with node.js and I've encountered an issue. I need to display the data of the currently logged in user in input fields. With the following code, I can access the data of the logged-in user and display it on the console: See O ...

What is the best way to ensure that my background image remains fully covering the screen even while scrolling or resizing

Struggling with implementing parallax scrolling through multiple images. Encountering two main issues: 1) Tiling occurs with repeated images or incomplete display, and 2) Inconsistent resizing on different screen sizes, particularly mobile phones. Any s ...

Grow your website horizontally rather than vertically for a unique user experience

When I align divs to the right, they start stacking up and crowding on top of each other. When there are more than 4 divs, the fifth one jumps below the rest as the page expands downward. I want to prevent this from happening. Instead, I would like the h ...

Can HTML be rendered within classes?

In the admin section of a website, I am working with multiple CRUD tables that require displaying success, information, or error messages when certain actions are performed, like deleting a record. This is a common practice that involves wrapping messages ...

Tips for encoding a base64 string into formats such as PDF, doc, xls, and png using jQuery, JavaScript, and HTML5

Need help handling base64 strings received from the server to save files in multiple browsers (IE, FF, Chrome). If receiving a PDF base64 string, how can it be saved in the browser? Also, if receiving an Image or Doc base64 string, what is the process fo ...

A set of dual menus displayed on a navigation bar

Is it possible to include two menus within a single navigation bar? I am looking to have a menu displayed on the left side and another menu on the right side. The menu on the right should remain visible and not collapse when the screen size changes. For ...

Create an HTML file to showcase the data fetched from my C# application

I'm currently working on creating a standalone EXE application that will generate an HTML document to showcase data retrieved from various APIs using C#. Struggling to find a straightforward method to accomplish this. Any recommendations or tips? ...

Is there a simple method to transform a Bootstrap Carousel into a seamless image scroll on smaller devices? My aim is for it to have a smooth scrolling experience similar to Instagram

Is it necessary to remove all the Bootstrap Carousel classes from the image elements in order for them to display as a column? I am seeking a responsive solution to switch from carousel to scroll. So far, I haven't attempted any changes yet. ...

How to retrieve the class of a dynamic div by clicking on a different div using jQuery?

I am trying to retrieve the class of a dynamic div when clicking on another div with the class name "div.secondclass". Below is my code snippet: $(document).ready(function() { $("div.secondclass").click(function () { firstclass=$('#firsti ...

I am looking to ensure that the ul li a() elements remain hidden until I hover over the h2 tag, at which point they will be displayed

Insert your code here : <table cellpadding="0" cellspacing="0" align="center" class="TblGreen"> <tr> <td> <h2><a href="#" class="AGreen">Sweater</a></h2> <p>The coding business</p> ...

Is there a way to display all of them inline in Woocommerce?

Can anyone assist with making each of these inline? https://i.sstatic.net/YF9bu.png <div class="atc_nsv"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <ul> <li><img class="ad lazyloaded" data-src="//cdn.shopif ...

Increase the border thickness around my title and add a border after an image

I'm encountering difficulties when trying to replicate the style showcased in this image using CSS. My specific challenge lies in creating a yellow horizontal line above the title "nossos numeros" and blue vertical lines between "Cursos", "Alunos", an ...

Tips for anchoring a row to the bottom of a Bootstrap webpage

After working with bootstrap, I am looking to position the last row of the page at the bottom in a fixed and responsive size manner. ...