How can I create a horizontal scrolling page layout?

I have created three different sections, and I want each of them to span the entire width of the screen. I was able to achieve this using the width property, but I am unsure how to make the height 100% of the screen. Additionally, I would like these sections to scroll horizontally instead of vertically as is typical. Is there a way to modify my code to achieve this?

Please refer to the snippet below:

body {
  margin: 0;
  padding: 0;
}
.element {
  width: 100%;
  background-color: #333;
  height: 100px;
  margin: 0;
  padding: 0;
}
.element2 {
  width: 100%;
  background-color: #000;
  height: 100px;
  margin: 0;
  padding: 0;
}
.element3 {
  width: 100%;
  background-color: #111;
  height: 100px;
  margin: 0;
  padding: 0;
}
.element p {
  padding: 0;
  font-family: "Bebas Neue";
  font-size: 50px;
  color: #ffffff;
  position: absolute;
}
.element2 p {
  padding: 0;
  font-family: "Bebas Neue";
  font-size: 50px;
  color: #ffffff;
  position: absolute;
}
.element3 p {
  padding: 0;
  font-family: "Bebas Neue";
  font-size: 50px;
  color: yellow;
  position: absolute;
}
<div class="element">
  <p>Element #1</p>
</div>

<div class="element2">
  <p>Element #2</p>
</div>

<div class="element3">
  <p>Element #3</p>
</div>

Answer №1

Consider utilizing flexbox and ensure that both html and body have the style of height: 100%;

html, body {
  height: 100%;
}
body {
  margin: 0;
  display: flex;
}
.element {
  flex: 0 0 100%;
}
.element1 { background: pink; }
.element2 { background: lightgreen; }
.element3 { background: lightblue; }
<div class="element element1">Element #1</div>
<div class="element element2">Element #2</div>
<div class="element element3">Element #3</div>

Answer №2

To achieve a side-by-side layout, change the display property of all your sections to inline-block.

.element { display: inline-block; }

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

Surround the image with a margin by wrapping text around it

Is it possible to display text in a div with a border and margin around an image using float: right? I have managed to get the text to wrap correctly around the image, but the border is positioned behind the image. UPDATE Here is a snapshot of how I wa ...

Does strip_tags() have vulnerabilities to scripting attacks?

Has there been any known XSS or other attack that can bypass the following code snippet? $content = "some HTML code"; $content = strip_tags($content); echo $content; This function does not modify any attributes on the tags that you allow using ...

Is there a way to remove an individual file from an HTML file input field?

I recently took on the task of implementing a delete function for an HTML file input with the type "file". The goal is to delete a single file from a list of multiple files. While deleting all files at once is simple, I am having trouble with my function t ...

Design element: Text overlaying background with a touch of transparency

Is there a way to create a background image with an opacity level of 0.5, while maintaining the text on top at full opacity (1) for better readability? Currently, the background image is not displaying as desired, and the opacity settings are affecting the ...

What is the best way to transmit a list item value through a form using a get or post request?

What is the best way to submit a list value using a form? I have a dynamically generated list and I want to send the value of a particular item that is clicked on. I could give each list item a separate name, but since my list is dynamically generated, ...

Switching the color scheme between mobile and desktop devices to make the background look

As a newcomer to threejs, I have just begun learning and developing with this technology. I am aware that certain features may be different on mobile browsers compared to desktop ones due to limitations. However, I have encountered an issue that I cannot s ...

Managing form submissions using Jquery and checkboxes

Whenever I submit my dynamically created form, all checkboxes briefly become selected for a split second. Does anyone have an explanation for this behavior? Is it common or is there something wrong with my code? Although the form submits correctly, it migh ...

Modify the color or background color of a disabled Material UI checkbox

The disabled unchecked checkbox appears too subtle to me, and I would like to enhance it by giving it a grey background and changing the cursor style to not-allowed. I've been trying to implement these styles on the checkbox using the makeStyles, but ...

Show the layout of the table in a visual format

I am struggling to showcase a table created using <ul> tags. I want the content to be displayed one after the other. Here is my code: CSS .activity-list-header > li { display: inline-block; text-align: left; width: 15.666%; list- ...

Vue.js is experiencing functionality issues on mobile devices and other connected devices, however, it is operating smoothly on desktop devices when localhost is running

I recently ran into an issue while trying to run my Laravel project on localhost and connect it to other devices like mobiles and desktops/laptops using the local address. The function works perfectly on the hosting desktop but fails to work on other devic ...

JQuery is capable of hiding a div using the .hide() method but is unable to reveal it using the

I am currently working on a basic webpage that includes a question and a set of radio buttons. Depending on the option selected by the user, the question will be hidden and either a correct or incorrect message will be displayed, both of which are initiall ...

Placing a user's username within an ejs template using express and node.js

Currently, I am attempting to integrate the username into a layout using ejs templating with node and express. Below are the steps I have taken: Mongodb model: const mongoose = require('mongoose') const Schema = mongoose.Schema; var uniqueValid ...

Mysterious behavior in JavaScript causes it to skip the second index of an array

Below is a lengthy snippet of html code that I would like to discuss: <!DOCTYPE html> <html> <head> <script type = "text/javascript" src="http://code.jquery.com/jquery-1.8.0.min.js"></script> <script> $( ...

How do I use PHP to dynamically generate lists in HTML with the <li> tag?

Is there a way to repeat the <li> element in this code snippet? I have been attempting to create a loop for the "<li>" block, but it keeps showing me an error. <?php $html .= " <li> <a href=''> <span& ...

Having trouble with the PHP WHERE query - it's not functioning

Recently delving into PHP, I have a requirement to verify a user's email in the database and redirect them to the next page if it exists. However, my SQL query seems to be malfunctioning in PHP but works fine in the SQL database. The structure of my ...

The maximum number of columns allowed in a flex layout in the direction of the

Can a maximum number of columns be set for a column-direction flexbox? I want to prevent the creation of a third column when the second one is filled. Instead, I prefer that the overflow extends both first columns while maintaining the element order. http ...

Learn how to utilize Selenium Web Driver with Java to interact with waypoints located within a map canvas on an HTML5 webpage

Struggling with Selenium Web Driver (Java) - How to interact with waypoints on an HTML5 canvas map? I am currently trying to implement drag and drop functionality on a canvas map within an HTML5 page, but I'm facing some challenges. https://i.sstati ...

How can you reset the chosen option in a Vue.js dropdown menu?

Within my dropdown menu, I have included a button that is intended to clear the selected city. Despite adding an event, the selected option is not being cleared. Can anyone provide insights on what I might be missing? Thank you in advance. Below is the bu ...

Weird Android CSS problem: mysterious white overlay appearing in all browsers, both zoomable and touch-sensitive

After testing my website in various browsers, I discovered that while it looks fine on most platforms, there is a persistent issue on Android devices. The problem occurs when the user scrolls down around 30% of the page - a white overlay appears and exten ...

What is the best way to initiate a function upon each page load?

(Apologies in advance for any English mistakes) Hello everyone, I am currently developing a simple Chrome extension to edit certain graphics and text fields on a website (Freshdesk) that cannot be modified directly on the site due to proprietary code. ...