Styling Your Website with Horizontal Div Layout using CSS

Assuming I have a nest structure like this:

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

Can a dynamic horizontal layout be achieved using just CSS?

In essence, the screen can only accommodate 2 vertical contents.

For instance, the screen can fit 3 vertical contents.

The body will display a horizontal scrollbar fixed at the bottom. When there is more content off-screen, it should flow left and move into a new column when the vertical space is filled. Any excess content should flow as indicated by the arrow.

Both screens must not show a vertical scrollbar. Is this possible without the need for JavaScript? I attempted using display: flex, but it did not produce the desired order effect mentioned above.

Please refer to the jsFiddle link: http://jsfiddle.net/W7z4s/10/ (Note that I want the .outer div to fill the body and show the scrollbar at the bottom)

It is imperative that this layout is supported on both Firefox and Chrome browsers!

Answer №1

One strategy to achieve this involves utilizing the :nth-child selector for float clearing and incorporating media queries such as @media screen and (max-height: 700px) to determine when and how elements should be cleared based on varying heights.

Answer №2

Attempting to utilize display: flex did not yield the desired order effect discussed earlier.

However, I found success with the following approach:

.outer {
    width:500px;
    height:500px;
    overflow:auto;
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    align-content: flex-start;
}

View updated fiddle

Please note that this solution may not currently work in Firefox due to lack of support for the flex-wrap property. However, based on data from caniuse, Firefox is expected to include support in version 28.

EDIT: (Updated FIDDLE with Firefox compatibility)

By using @supports, we can temporarily employ the -moz-colums-count for Firefox while waiting for flex-wrap support - a technique similar to Modernizr but purely through CSS.

The advantage here is that Firefox does support these queries.

Therefore, including the following code snippet:

@supports (not (flex-wrap: wrap)) and (-moz-columns: 4) {
    .outer { 
        -moz-column-count: 4;
        column-count: 4;
        display: block;
        width:120%;
    }
}

Now, Firefox will implement CSS columns while other browsers continue to use flexbox styling.

Answer №3

Although unconventional and messy, there is a way to achieve this layout by utilizing CSS transform properties. By rotating the parent div 90 degrees and then counter-rotating the child div, we can create vertical rows.

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Vertical Rows - Unconventional Method</title>
<style>
html, body, .wrapper {
    background-color: #666;
    height:100%;
    width:100%;
    box-sizing:border-box;
}
.wrapper {
    padding: 50px;
    margin: 5%;
    height: 90%;
    width:90%;
    position: relative;
}
.container {
    position: absolute;
    left:15px;
    top: 15px;
    transform:rotate(-90deg);
}
.container div {
    width:150px;
    height: 150px;
    background-color: #ccc;
    float:right;
    margin: 20px;
    transform: rotate(90deg);
}
</style>
</head>

<body>
<div class="wrapper">
<div class="container">
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
    <div>7</div>
    <div>8</div>
    <div>9</div>
    <div>10</div>
    <div>11</div>
    <div>12</div>
    <div>13</div>
    <div>14</div>
    <div>15</div>
    <div>16</div>
    <div>17</div>
    <div>18</div>
</div>
</div>
</body>
</html>

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

When performing web scraping with Puppeteer, employing a single selector to target various types of data

As a budding web developer, I have recently delved into coding. My current knowledge is limited to HTML, CSS, JS, and NODE. Currently, I am working on a project involving page scraping and utilizing puppeteer. CHALLENGE - In scenarios like the o ...

How can we make sure the selected tab opens in jQuery tabbed content?

I'm trying to make my tabbed content open on a specific tab by changing the URL. I remember seeing something like this before but can't seem to find it! Here's the fiddle I created: http://jsfiddle.net/sW966/ Currently, the default tab is ...

Malfunctioning carousel

I've been attempting to set up a carousel, but it's not functioning properly. I'm unsure of where the issue lies. The navbar section is working fine, but the carousel isn't appearing at all. Should the carousel be placed above the navba ...

What is the best method for determining the current value of an On/Off switch with labels for both states?

How can I retrieve the current value of an On/Off switch that is labeled as On and Off? Below is the HTML code for this particular switch: <div class="make-switch has-switch"> <div class="switch-on switch-animate"> <input type="checkbox" d ...

Ways to ensure that two divs have equal heights based on whichever one has the greater height using CSS

I need help with adjusting the heights of two divs inside a container div using CSS. Specifically, I want the height of the img_box div to match the height of the content_con div based on their actual content. For example, if the content_con div contains t ...

Utilize Bootstrap 4 to create a full screen desktop layout with columns that automatically adjust to

I am struggling to create a full-screen layout using Bootstrap 4, similar to the one shown in this image. I'm facing issues with the left and right columns not taking up the remaining space between the navigation and footer sections. Additionally, I n ...

Unable to move to a different HTML page following validation with JavaScript

Recently, I completed a HTML page that consists of two separate sections - one for logging in and the other to display after a successful login. In order to ensure proper validation on the login.html page, I implemented the following: However, when attemp ...

Guide to inserting an HTML file into an article's content

After downloading an extension from freefrontedit and uploading it to my server in the directory /accordeon, I successfully accessed it by pointing my browser to . However, I am now faced with the challenge of loading the index.html into my Joomla article ...

What are some strategies to stop a jQuery UI button created with a link from inheriting the link's text color?

I recently came across a recommendation to create a jQuery button on top of a link for redirect purposes: <a href="/search" class="button">My link</> $(".button").button(); However, I noticed that if the button class has a red foreground colo ...

What is the method for manually setting the page_source in Python3 using Selenium?

Currently, I am developing an application utilizing selenium. My understanding is that the webdriver.Firefox's get method can be used to retrieve a webpage in the following manner: driver = webdriver.Firefox(executable_path=r'geckodriver&apo ...

Concerns regarding rendering HTML and drawing in Node.js

Having an issue where node.js is serving an html file with an SVG drawing. The index.html features a chart similar to the line chart found at http://bl.ocks.org/mbostock/3883245 Whenever I try to serve the index.html through the express server, I end up ...

Guide on showcasing the values from two text fields with autocomplete suggestions in a third text field

Hey there, I have a search form that takes values from two text fields and combines them to populate a third text field for querying. <form name="form1" method="post" action="" autocomplete="off" oninput="sea.value = password.value +''+ passw ...

What is the best way to ensure a consistent time interval between invoking two functions in JavaScript?

Is there a way to create a code that will call one function, let's say toStart(), and then immediately call another function, toStop(), exactly two seconds after the first function is initiated? I want this process to continue until a specific button, ...

What is the best way to ensure that my placeholder text remains permanent and properly formatted?

Looking to create a basic typing test app using HTML, CSS and JS. My goal is to have placeholder text displayed in the input box so users know what to type as they type. Misalignments between the placeholder text and user input will indicate mistakes. Afte ...

What is the best way to measure the timing of consecutive events within a web browser, utilizing JavaScript within an HTML script tag?

Currently delving into the realm of JavaScript, transitioning from a Java/Clojure background, I am attempting to implement a basic thread-sleep feature that will display lines of text on the screen at one second intervals. Initially, I considered using t ...

Issue with Bootstrap 5 justify-content causing misalignment and inability to vertically center content

I've encountered a coding challenge while working with Bootstrap 5: <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5e3c31312a2d2a2c3f2e1e6b706e706c">[email protected]& ...

Using Spring Boot RestController to Serve HTML Pages

I'm having trouble accessing the HTML page I created. Here is an overview of my project: https://i.sstatic.net/Wvmus.png This is the "IndexController" class: @RestController @AllArgsConstructor @RequestMapping(path = "/webpage") public class IndexCo ...

Issue with Submitting Form in IE11 through Iframe with Jquery

In the code snippet below, there is an issue where the alert function should be executed after the form submission. However, it only executes the first time and then fails to do so thereafter. This problem is prominent in IE11, as the alert works fine in a ...

Stop iframes from redirecting the parent page

I'm currently facing a unique situation on my website where I have an iframe within the same domain. Unfortunately, due to deployment issues, I am unable to access the code inside the iframe. Whenever the iframe loads, it triggers a redirection on th ...

What is the most efficient method for recursively cleaning HTML files on a drive?

Need a script to clean HTML files by removing all content after the </HTML> tag in multiple files within a partition. This is essential for restoring web server content that has been infected or injected with malicious code. ...