Tips on creating horizontal scrolling for rows once they hit the maximum width

I need the content to scroll horizontally if it exceeds the maximum width. I have tried setting the width to 100%, using overflow-x:auto, and white-space: nowrap as suggested in other stackoverflow threads, but it doesn't work for Bootstrap columns. I also attempted using flexbox with overflow property and adding container-fluid, but the outcome remains the same - the scrollbar is visible but not functional.

Currently, if the number of columns exceeds 18, they break onto a new line instead of scrolling, which is not my desired behavior. I want them to be able to scroll horizontally without breaking onto a new row.

<div class="col-xs-12 col-sm-12 col-md-9 col-lg-9">
   <div class="container-fluid p-0">
      <div style="width:100%; overflow-x:auto; white-space: nowrap;">
         <form id="TICKETSALE_ORDERTICKETSELECTSEATFORM" action="TICKETSALE_ORDERTICKETSELECTSEATFORM.php" method="POST">
            <div class="row row-eq-height mb-4 px-2 py-2" style="background-color:purple; height:40px;">
               <div class="col-sm-12" align="center">
                  <div class="row">
                     <div class="col-sm-12" >
                        <label class="text-center " style="color:white; font-weight:900;">SCREEN</label>
                     </div>
                  </div>
               </div>
            </div>
            <?php
                for($a=1; $a<=$row_Q1[0]['ROW']; $a++){
                    //row
            ?>
               <div class="row row-eq-height ">
            <?php
               for($b=1; $b<=$row_Q1[0]["COL"]; $b++){
                  //col
            ?>
               <div class="col">
            <?php
               $RowKeyExist = checkIfKeyExist($row_Q2, $a, $b);
                  if($RowKeyExist!== false){
            ?>
                     <div id=<?=$a.",".$b?>>
                        <div class="form-check pl-0">
                           <label class="fas fa-chair SEATIMAGE">
                           <?php
                              if($row_Q2[$RowKeyExist]["TICKETCODE"]=='1'){ //"1" is booked
                                 echo "style='font-size:25; font-family: Font Awesome\ 5 Free; display: inline-block; content: \f630; font-weight: 900; color:grey;'";
                              }elseif($row_Q2[$RowKeyExist]["TICKETCODE"]=='2'){ //"2" is bought
                                 echo "style='font-size:25; font-family: Font Awesome\ 5 Free; display: inline-block; content: \f630; font-weight: 900; color:red;'";
                              }elseif($row_Q2[$RowKeyExist]["TICKETCODE"]=='0'){ //"0" is temp bought in db and not current user
                                 echo "style='font-size:25; font-family: Font Awesome\ 5 Free; display: inline-block; content: \f630; font-weight: 900; color:grey;'";
                              }elseif($row_Q2[$RowKeyExist]["TICKETCODE"]==null){ //"null" is vacant
                                 echo "style='font-size:25; font-family: Font Awesome\ 5 Free; display: inline-block; content: \f630; font-weight: 900; color:green;'";
                              }
                           ?>
                          </label>
                           <div>
                              <label><?=$row_Q2[$RowKeyExist]["SEATLABEL"];?></label>
                           </div>
                        </div>
                     </div>
                  <?php
                     }else{
                  ?>
                     <div class="d-none">
                        <label class="fas fa-chair SEATIMAGE" style="font-size:25; font-family: Font Awesome\ 5 Free; display: inline-block; content: \f630; font-weight: 900; color:purple;"></label>
                        <div>
                           <label>NONE</label>
                        </div>
                     </div>
                  <?php
                     }
                  ?>
                  </div>
               <?php
                  }
               ?>
               </div>
            <?php
               }
            ?>
         </form>
      </div>
   </div>
</div>

Answer №1

Here is a practical demonstration of the desired outcome.

<!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">
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">
    <style type="text/css">
        .my-div {
            width: 300px;
            background-color: red;
            color: white;
            border: 2px solid white;
            display: inline-block;
        }
    </style>
  </head>
  <body>
    <div class="container">
        <div class="row">
            <div class="col-md-12" style="overflow-x: scroll; white-space: nowrap;">
                <div class="my-div">
                    my div   
                </div>
                <div class="my-div">
                    my div
                </div>
                <div class="my-div">
                    my div
                </div>
                <div class="my-div">
                   my div
                </div>
                <div class="my-div">
                    my div
                </div>
            </div>
        </div>
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
  </body>
</html>

Answer №2

/* Styling for a testimonial group */
.testimonial-group > .row {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
}
.testimonial-group > .row > .col-xs-4 {
  flex: 0 0 auto;
}

/* Custom Decorations */
.col-xs-4 { color: #fff; font-size: 48px; padding-bottom: 20px; padding-top: 18px; }
.col-xs-4:nth-child(3n+1) { background: #c69; }
.col-xs-4:nth-child(3n+2) { background: #9c6; }
.col-xs-4:nth-child(3n+3) { background: #69c; }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<div class="container testimonial-group">
  <div class="row text-center">
    <div class="col-xs-4">1</div><!--
 --><div class="col-xs-4">2</div><!--
 --><div class="col-xs-4">3</div><!--
 --><div class="col-xs-4">4</div><!--
 --><div class="col-xs-4">5</div><!--
 --><div class="col-xs-4">6</div><!--
 --><div class="col-xs-4">7</div><!--
 --><div class="col-xs-4">8</div><!--
 --><div class="col-xs-4">9</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

A guide on implementing CSS and Styling in a React component

Struggling to style my React.js file that was converted from a standard web page. I have the original CSS but unsure how to use React for proper styling. Any assistance is welcomed! var NavBar = React.createClass({ render: function() { return ( ...

Tips for creating scrollable popovers in Bootstrap 4

I came across a similar question, but the solution provided didn't work for me and I'm not sure why. Why is my popover content not scrolling when it exceeds 50px? Also, a side question: I'm facing an issue with newlines within the popover wh ...

The hovering of the mouse over a dropdown menu causes a division on the page to shift

Creating a website with a dropdown menu and slider division can be tricky. When hovering over the menu, the submenu displays but causes the slider division to shift down. Does anyone have suggestions on how to fix this issue? Below is the code: <html& ...

Accessing PHP variables within the HTML portion of a PHP document

Setting up my own contact form for the first time using PHP has been a learning experience. While I am able to receive emails from the form, I'm struggling to display the user-inputted information in the email. The HTML <label for="name"> ...

The image being displayed is significantly wider than the corresponding HTML element

I'm attempting to display this webpage in PNG format using npm's wkhtmltox: <!doctype html> <html> <head> <meta charset="utf-8"> <style> html, body { padding: 0; width: 340px; } ...

Jquery problems impacting every element rather than only one

I'm currently experimenting with a small project where I have multiple div elements containing an image, h1 tag, and p tag all sharing the same class name. My goal is to add CSS effects that make the h1 tag and p tag slide into view and become visible ...

Preventing image overlap in Bootstrap when window size is reduced

Here is the code snippet: <div id="members"> <div class="container-fluid"> <div class="row"> <div id="members" class="col-md-12 text-center"> <h3>Text</h3> &l ...

Retrieve the image source when clicking on multiple posts that share the same div class and button class

<script src="https://code.jquery.com/jquery-1.11.1.js"></script> <script> $(function(){ $('.like').click(function(e){ e.preventDefault(); // stop the page from reloading alert( $('.post-container&apos ...

What is the reason behind receiving a CSS warning stating "Expected color but found '0' " when using Phaser's setText() function?

Here's how I created my text object: statusBarHP.text = game.add.text(0, 0, '', { font:"16px Arial", fill:"#ffffff", stroke:"#000000", strokeThickness:2 }); For the object that holds the text: statusBarHP = game.add.sprite ...

Refreshing certain sections of a webpage without the need to refresh the entire page

If you want to understand better, it would be helpful if you could check out my website first at: The main part of the website is a stream from Own3D.tv displayed through an iframe (line 342). My objective is to have the ability to click on a specific str ...

Jumbling a word by shuffling its letters into a random order

The objective of the program is to take the word you input into a box, split it into an array of letters, and then shuffle them. Following that, it should capitalize the first letter and lowercase the rest before displaying the result in the same box. I a ...

Error: Unable to modify the div content - Uncaught TypeError: Unable to assign value to innerHTML of null

Attempting to update the contents of a div using JavaScript and innerHTML, but encountering an issue. After implementing the code to change the div's content, the functionality stopped working. The syntax has been double-checked. Tools being used in ...

Why Safari is Not Displaying Drop Shadows on SVG Path Elements in CSS

I implemented an SVG triangle using HTML: path { fill: red; filter: drop-shadow(5px 3px 17px rgb(0 0 0 / 1)); } <svg style="height: 36px; width: 100%; background-color: #EAEAEA ;" viewBox="0 0 436 217" preserveAspectRatio="none" class="Tagline ...

How can I transform a multidimensional array in PHP into a nested list in HTML?

I am working with an array that is nested and can be "endless" due to the complexity of family trees. Here is a simplified example: Array ( [id] => 121 [name] => Very Important Dogs Bowey Showey [gen] => 0 [mother] => Array ...

Guide to creating an endless loop animation within a frame

<div className="sound-wave-container py-8"> <img src={!recording ? Wave : DottedLine} className={!recording ? "sound-wave" : ""} alt="Sound Wave" /> </div> ...

Stop Element-UI from automatically applying the list-item style to li elements

I have a list of data elements that I am rendering in the following way: <ul> <li v-for="el in elements"> {{el.data}} </li> </ul> Here's how I style it in my .css file: ul { list-style-type: none; padd ...

json success function not being triggered

I am facing an issue with executing the success function in my code while trying to post the value of an input box and retrieve the value of a checked radio button. The objective is to perform a query based on which radio button is checked. Here is the HT ...

What technique works best for changing the visibility of an image without causing other elements to shift position?

On my webpage, I have a table cell with an image that should only display when hovering over the cell. The problem is that when the image is shown, it shifts the other text to the left because its default state is "display:none". I'm searching for a s ...

Is it possible to override Bootstrap or not?

It's quite a puzzle to figure out when I can and cannot override Bootstrap classes or IDs with custom CSS. For instance, it seems easy enough to change the default navbar-dark background and font style, but altering the font color and size proves to ...

Creating a sleek horizontal scrolling list with the least amount of rows using tailwindcss

Is there a way to create a 3-row list with horizontal scroll without the unwanted space between items? I've been using tailwindcss and grid to achieve this layout, but I'm encountering issues with spacing: https://i.stack.imgur.com/WeRyQ.png Cu ...