You cannot position three DIVS side by side

After conducting an extensive search and reviewing numerous threads on the topic, I am still unable to resolve this issue.

The concept is simple: I want to display 3 containers side by side, each independently vertically scrolling images.

The CSS animation is operational, with the following code snippet:

#scroll-container {
    height: 600px;
    width: 600px;
    overflow: hidden;
    display: inline-block;
}

#scroll-container img {
    max-width: 100%;
    max-height: 100%;
}

#scroll-text-1 {
    height: 100%;
    transform: translateY(100%);
    animation: my-animation-1 60s linear infinite;
}

#scroll-text-2 {
    height: 100%;
    transform: translateY(-100%);
    animation: my-animation-2 60s linear infinite;
}
  
@keyframes my-animation-1 {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(-550%);
    }
}

@keyframes my-animation-2 {
    from {
        transform: translateY(-550%);
    }
    to {
        transform: translateY(100%);
    }
}

my-animation-1 scrolls from bottom to top and my-animation-2 scrolls from top to bottom. The challenge arises when attempting to implement HTML code similar to the one below (using plain text instead of images):

<!DOCTYPE html>
<html lang="de">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link type="text/css" rel="stylesheet" href="../css/article.css">
        <title>Artikelliste Page</title>
    </head;

    <body>
        <div id="scroll-container">
            <div id="scroll-text-1">
                <!--Insert images here-->
                Text<br>
                Text<br>
                Text<br>
                Text<br>
                Text<br>
                Text<br>
                Text<br>
                Text
            <div>
        </div>
        <div id="scroll-container">
            <div id="scroll-text-2">
                <!--Insert images here-->
                Text<br>
                Text<br>
                Text<br>
                Text<br>
                Text<br>
                Text<br>
                Text<br>
                Text
            <div>
        </div>
        <div id="scroll-container">
            <div id="scroll-text-1">
                <!--Insert images here-->
                Text<br>
                Text<br>
                Text<br>
                Text<br>
                Text<br>
                Text<br>
                Text<br>
                Text
            <div>
        </div>
    </body>
</html>

Unfortunately, the divs are not aligning as intended. Only the first container appears while the other two remain invisible on the page, offset or overlapping each other incorrectly.

In my troubleshooting efforts, I attempted to hide the first container using developer tools to assess potential overlaps, but all it resulted in was the entire page turning blank. Despite the code being present in the dev console, the actual content failed to render.

Further attempts that proved futile include:

1. float: left;

2. display: inline-block;

3. Creating a wrapper around the containers with either float: left; or display: inline-block;

It became clear that these options would be effective if all three containers appeared successfully on the page. This suggests a different underlying issue that eludes my understanding.

EDIT: Even adding excessive br tags beneath the containers did not yield any visible changes, almost as if the code is vanishing into thin air within a mysterious void...

Answer №1

Your HTML code was flagged as invalid.

To rectify, I consolidated the three instances of #scroll-container into one parent div that contains #scroll-text-1, #scroll-text-2, and #scroll-text-3. Additionally, I applied the following CSS properties to the #scroll-container to align all children side by side:

display:flex; align-items:center; justify-content:space-around;

I also maintained only one animation for simplicity.

#scroll-container {
    height: 600px;
    width: 600px;
    overflow: hidden;
    display: flex;
    align-items:center;
    justify-content:space-around;
  }
  
#scroll-container img {
    max-width: 100%;
    max-height: 100%;
}
#scroll-text-1 {
    height: 100%;
    transform: translateY(100%);
    animation: my-animation-1 10s linear infinite;
  }

#scroll-text-2 {
    height: 100%;
    transform: translateY(-100%);
    animation: my-animation-1 10s linear infinite;
}
#scroll-text-3 {
    height: 100%;
    transform: translateY(-100%);
    animation: my-animation-1 10s linear infinite;
}
  
  @keyframes my-animation-1 {
    from {
      transform: translateY(100%);
    }
    to {
      transform: translateY(-550%);
    }
  }
<div id="scroll-container">
        <div id="scroll-text-1">
            <!--Insert images here-->
            Text<br>
            Text<br>
            Text<br>
            Text<br>
            Text<br>
            Text<br>
            Text<br>
            Text
        </div>
        <div id="scroll-text-2">
            <!--Insert images here-->
            Text<br>
            Text<br>
            Text<br>
            Text<br>
            Text<br>
            Text<br>
            Text<br>
            Text
        </div>
        <div id="scroll-text-3">
            <!--Insert images here-->
            Text<br>
            Text<br>
            Text<br>
            Text<br>
            Text<br>
            Text<br>
            Text<br>
            Text
        </div>
    </div>

Answer №2

There were a couple of broken closing tags in your code, and it's recommended to use unique IDs on the page. The second column animation may take some time to fully populate.

#content-container {
    height: 600px;
    width: 33%;
    overflow: hidden;
    display: inline-block;
    float: left;
}
#content-container-2{
    height: 600px;
    width: 33%;
    overflow: hidden;
    display: inline-block;
    float: left;
}
#content-container-3 {
    height: 600px;
    width: 33%;
    overflow: hidden;
    display: inline-block;
    float: left;
}

#scroll-text-1 {
    height: 100%;
    transform: translateY(100%);
    animation: fade-up 60s linear infinite;
  }

#scroll-text-2 {
    height: 100%;
    transform: translateY(-100%);
    animation: fade-down 60s linear infinite;
}
  
  @keyframes fade-up {
    from {
      transform: translateY(100%);
    }
    to {
      transform: translateY(-550%);
    }
  }

  @keyframes fade-down {
    from {
      transform: translateY(-550%);
    }
    to {
      transform: translateY(100%);
    }
  }
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link type="text/css" rel="stylesheet" href="../css/article.css">
        <title>Article List Page</title>
    </head>

    <body>
        <div id="content-container">
            <div id="scroll-text-1">
                <!--Insert images here-->
                Text1<br>
                Text<br>
                Text<br>
                Text<br>
                Text<br>
                Text<br>
                Text<br>
                Text
            </div>
        </div>
        <div id="content-container-2">
            <div id="scroll-text-2">
                <!--Insert images here-->
                Text2<br>
                Text<br>
                Text<br>
                Text<br>
                Text<br>
                Text<br>
                Text<br>
                Text
            </div>
        </div>
        <div id="content-container-3">
            <div id="scroll-text-1">
                <!--Insert images here-->
                Text3<br>
                Text<br>
                Text<br>
                Text<br>
                Text<br>
                Text<br>
                Text<br>
                Text
            </div>
        </div>
    </body>
</html>

Answer №3

Little did I know, it was merely an unclosed tag <div> causing all the trouble... Moving forward, I am committed to exploring various solutions that are more efficient and polished. It may have been a major setback and a beginner's blunder, but I appreciate everyone's patience and understanding.

Answer №4

If you're looking to create a layout like this, flexbox is the way to go:

body {
  margin: 0;
}

#wrap {
  background: goldenrod;
  height: 100vh;
  width: 100vw;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  flex-flow: row wrap;
}

.scroll-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: min(90%, 100px);
  margin: 10px;
  padding: 10px;
  background: white;
}

.scroll-container__item {
  height: 30px;
  width: 90%;
  background: darkorchid;
  margin: 5px 0;
}
<div id="wrap">
  <div class="scroll-container scroll-container--one">
    <div class="scroll-container__item"></div>
    <div class="scroll-container__item"></div>
    <div class="scroll-container__item"></div>
    <div class="scroll-container__item"></div>
    <div class="scroll-container__item"></div>
    <div class="scroll-container__item"></div>
    <div class="scroll-container__item"></div>
    <div class="scroll-container__item"></div>
  </div>
  <div class="scroll-container scroll-container--two">
    <div class="scroll-container__item"></div>
    <div class="scroll-container__item"></div>
    <div class="scroll-container__item"></div>
    <div class="scroll-container__item"></div>
    <div class="scroll-container__item"></div>
    <div class="scroll-container__item"></div>
    <div class="scroll-container__item"></div>
    <div class="scroll-container__item"></div>
  </div>
  <div class="scroll-container scroll-container--three">
    <div class="scroll-container__item"></div>
    <div class="scroll-container__item"></div>
    <div class="scroll-container__item"></div>
    <div class="scroll-container__item"></div>
    <div class="scroll-container__item"></div>
    <div class="scroll-container__item"></div>
    <div class="scroll-container__item"></div>
    <div class="scroll-container__item"></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

Combining multiple rows into a single row and inserting a new column

Hi there, I'm currently diving into the world of programming and tackling a project involving PHP and MySQL. However, I've encountered a bit of a roadblock. My current setup involves a table named marks, where each time a mark is added to a stud ...

Creating a gradient circle in the header menu of your WordPress site

I am absolutely in love with the half CSS gradient circle featured on this WordPress website, but I'm struggling to implement it myself. Here is the URL for reference: Could someone please provide me with detailed instructions on how to achieve this ...

A variety of personalized Vimeo play buttons

Recently, I stumbled upon a genius solution by Chris Coyier for creating custom Vimeo play buttons. It worked perfectly for my needs, but now I'm facing a challenge - how to make it function with multiple videos on the same page. I tried swapping out ...

Dynamic HTML text colors that change rapidly

I have an interesting question to ask... Would it be possible to create text that switches between two colors every second? For example, could the text flash back and forth between red and grey? I don't mean changing the background color, I mean act ...

AngularJS - ensuring unique select options are displayed for each distinct value

I currently have a HTML select box positioned at the top of a page that displays a list of documents. This select box contains available file extensions which can be used to filter the document list. The code snippet I am using is as follows: <select d ...

Discrepancy detected in AGM Map printout

When attempting to print my Angular AGM Map from Chrome, I noticed a large grey gap in the map. This gap is visible even when "background graphics" are turned off and it causes the map image below it to shift downwards. If you want to reproduce this issue ...

How to disable the click handler of a div using only classes

Although I'm not an expert in HTML, I am eager to create a basic bootstrap button in HTML that can be enabled and disabled. My question relates to the following scenario: <div class="button" onClick=doSomething >My Button</div ...

The submit button is not reading the JavaScript file for validation and instead goes directly to my PHP file

**Hello, I'm new to Stack Overflow. My submit button is not reading the JavaScript file I created; instead, it goes straight to the PHP file without validating the input fields first in the JavaScript file. I've been stuck here for hours and can& ...

What is the reason behind the CSS not rendering when async:false is used?

I find it peculiar and am actively seeking an explanation for this anomaly. In my code snippet, the AJAX call seems to be causing unexpected behavior: $('.edit-config').click(function() { var that = this; var msg; ip ...

Adjust the variable's value

After clicking on the "Add to Cart" button, the value is added to ".total-cart". When an option is selected in , its value is also added to the total cart value and displayed in ".total-all". However, clicking "Add to Cart" again does not update the value ...

Uniquely tag an uploaded file

My code for uploading files is as follows: var xhr = new XMLHttpRequest(); xhr.upload.addEventListener("progress", uploadProgress, false); xhr.open("POST", requestUrl, true); xhr.send(f); I want to draw your attention to the fact that I have attached a l ...

CSS codes are ineffective when used simultaneously

Looking for help with my CSS code situation involving opacity on images: CSS for Opacity: .hover:hover { opacity:0.8;} HTML for Opacity: <a href="http://www.byggprojektoren.se"> <img class="hover" src="http://byggprojektoren.se/wp-content/u ...

Changing the scrolling behavior of an iframe

I'm attempting to update the layout of to resemble . To achieve this, I've created a page with an iframe. However, I'm facing an issue with the iframe scroll function, as it does not match the desired design. I've experimented with t ...

When I implemented snap.js on my main content wrapper, I noticed that it was causing a disruption in a few of my jQuery functions

Currently, I am utilizing snap.js to allow the sliding of the main content div using css3 and javascript, exposing a menu beneath. However, I am encountering an issue when I apply the class snap-content to specify which div snap.js should slide - which is ...

How to incorporate spacing within table rows using HTML

I am trying to create a table with rows starting from different positions like this 12345 678910 This is my code <table class="center"> <tr style="padding-right: 22%"> <td>1</td> <td>2</td> ...

Bootstrap modal for interactive table rows

I'm working with a 3-rowed table and I want to be able to click on each row and display more information about the content in a modal pop-up. However, when I attempt to click on a row, the screen darkens but the pop-up does not appear. <!DOCTYPE h ...

Learn how to efficiently redirect users without losing any valuable data after they sign up using localStorage

I am currently facing an issue with my sign up form. Whenever a user creates an account, I use localStorage to save the form values. However, if the user is redirected to another page after hitting the submit button, only the last user's data is saved ...

Guide to correctly inserting an image into a webpage using JavaScript

Currently, I am working on a tutorial for creating a dynamic webpage. The objective is to display the time and an image that changes based on the current hour. However, the method used by the instructor to insert the image is unfamiliar to me, and despit ...

Tips for maintaining consistent formatting of a div element across various sizes

Looking to create a Bootstrap Jumbotron that features a background image, text (h1 and p), and a call-to-action button that scales appropriately for different viewports without sacrificing formatting. Essentially, the goal is for the div to behave like an ...

Ways to showcase an icon within a select options tag

Is there a way to show Font Awesome icons in select options tag? I have tried using it outside like this <i class="fas fa-chart-pie"></i> But I'm not sure how to display it within the <option> tags instead of text. <select id="s ...