Scrolling horizontally in the Bootstrap grid system

I am currently working on a project where I want to implement horizontal scrolling using Bootstrap for items instead of the default vertical scrolling. Here is an example:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
  <div class="row">
    <div class="col-sm-4" style="background-color:red;">item1</div>
    <div class="col-sm-4" style="background-color:blue;">item2</div>
    <div class="col-sm-4" style="background-color:green;">item3</div>
    <div class="col-sm-4" style="background-color:yellow;">item4</div>
  </div>
  <div class="row">
    <div class="col-sm-4" style="background-color:red;">item5</div>
    <div class="col-sm-4" style="background-color:blue;">item6</div>
    <div class="col-sm-4" style="background-color:green;">item7</div>
    <div class="col-sm-4" style="background-color:yellow;">item8</div>
  </div>
</div>
</body>
</html>

My goal is to make 'item4' and 'item8' visible only when users scroll left or right, but unfortunately with Bootstrap they are positioned below 'item1' and 'item5' respectively.

Answer №1

If you want to adjust the layout of your divs, consider changing the numbering.

With Bootstrap's grid sizing at 12, using col-sm-4 will display a maximum of 3 per line (4 + 4 + 4 = 12).

To show 4 items per line, try using col-sm-3, which takes up 25% of the container space (3 + 3 + 3 + 3 = 12).

In summary, here's a suggestion:

<div class="row">
    <div class="col-sm-3" style="background-color:red;">item1</div>
    <div class="col-sm-3" style="background-color:blue;">item2</div>
    <div class="col-sm-3" style="background-color:green;">item3</div>
    <div class="col-sm-3" style="background-color:yellow;">item4</div>
  </div>
  <div class="row">
    <div class="col-sm-3" style="background-color:red;">item5</div>
    <div class="col-sm-3" style="background-color:blue;">item6</div>
    <div class="col-sm-3" style="background-color:green;">item7</div>
    <div class="col-sm-3" style="background-color:yellow;">item8</div>
  </div>

For more information on Bootstrap Grid system, check out this link:

http://getbootstrap.com/css/#grid

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

What sets SVG and CSS3 animations apart and where do they overlap?

Sencha Animator relies on CSS3 animations as its primary animation tool. RaphaelJS, on the other hand, favors SVG animations for its visual effects. I'm curious about the parallels and distinctions between SVG and CSS3 animations. Is either one a s ...

What steps can be taken to adjust the alignment of a Bootstrap Dropright menu so that it opens in an upward direction instead of the standard downward

My dropdown menu is dropping towards the right correctly, but it is going downwards and getting hidden under my page. I want it to open upwards instead of downwards. I attempted to adjust the CSS, adding bottom:0 to the dropdown-menu, but unfortunately, i ...

Do you think there might be an issue with the CSS coding?

I have designed a user-friendly responsive login form that allows users to easily log in and reset their passwords. However, I am facing an issue where the username and password fields are not displaying on separate lines as intended. I have thoroughly ins ...

How to Delete an Added Image from a Dialog Title in jQuery

I've tried multiple solutions from various sources, but I'm still struggling to remove an image from a dialog. Whenever I attempt to do so, I end up with multiple images instead of just one. It's important to note that I only want the image ...

What is the best way to create pages that showcase 10 posts each?

Currently, I am facing a challenge with displaying 100 posts using the Fetch API on one single page. I am looking for a way to create separate pages where each page would showcase only 10 posts. Below is my existing JavaScript code: fetch('htt ...

The presence of floats in CSS influence the surrounding div elements

Currently experimenting with HTML/CSS utilizing Bootstrap v5.0 and encountering issues with the unusual interactions between floats and divs. Specifically, aiming to achieve the following: https://i.sstatic.net/4lpC2.png Successfully achieved the desired ...

Guide on how to align the bootstrap popover's arrow tip with a text field using CSS and jQuery

I have tried multiple solutions from various questions on Stack Overflow, but I am still struggling to position the arrow tip of the bootstrap popover correctly. html: <input type = "text" id="account_create"/> js: $('.popov ...

Upgrading Numbers with Jquery, Ajax, and PHP

Currently, I am attempting to create an incrementer that functions similarly to the one on this website: . However, it seems like there is a piece of code missing in order for it to work properly. Can anyone point out what I might be overlooking to make th ...

Is it possible to capture a screenshot of a YouTube video at a specific moment?

Imagine a scenario where we have a function called getScreenShot. We invoke it in the following manner: scrShot=getScreenShot(videoID, time, quality) This function is designed to capture a screenshot of the video at the specified time (e.g. 1:23) and in t ...

Go through each row in a table and retrieve the value of a column only if the checkbox

Is there a way to extract only the values in the serial column if the checkbox is checked for that row using jquery? I am currently able to retrieve the serial value, but unsure how to incorporate the checkbox condition. HTML: <table id="usersTable"&g ...

What is the method for setting a fixed size for a Bootstrap container?

Bootstrap 4 is the framework I am currently using. Below is the HTML code I have written: <div class="sprite container d-inline-block bg-info rounded p-1"> <span class="sprite-span-level">Top-right text over image</span> <img cl ...

Tips for connecting a DOM element when a link is clicked

I am currently browsing http://localhost:8000/index.html My goal is to navigate to localhost:8006/someAddress and interact with an element with the id '157579' as well as click on a button with the id '1787' that will trigger a change ...

Icons will be displayed when hovered over

Is it possible to display icons on hover in a div and hide them otherwise using just CSS? Or do I need to use javascript for this function? Thanks in advance! Example: HTML: <div id="text_entry"> <p>Some text here</p> <span ...

Passing Data Between Blazor App Pages Using .NET Core

Recently, I began learning how to create websites using the Blazor template. I'm having trouble figuring out how to pass data from one page to another. It's quite different compared to .NET CORE MVC web applications and I haven't been able t ...

Utilizing JavaScript to dynamically resize an element within a slide as soon as the slider transitions to the following slide

RESOLVED! ISSUE FIXED! While working on my personal website using WordPress and the Smart Slider 3 plugin, I encountered a problem with the positioning and size of an element in the second slide. Despite finding a tutorial explaining how to manually trigg ...

Leveraging jQuery to automatically fill in a time field while excluding other buttons

I've been working on using jQuery to automatically fill in a time input field. The functionality is working properly, but the time is also being applied to my other button. How can I make sure it only gets assigned to the time input field? I would re ...

What is the best way to use canvas to precisely draw a line on the display at specific absolute coordinates?

As a newcomer to working with canvas and SVG, I am trying to create a line between two specific coordinates. For example, if I have two rectangles, I need to draw a line connecting their centers: https://i.sstatic.net/Rc6qA.png Here is what I have tried ...

Can I split icons instead of combining them when stacking in Font Awesome?

Is it possible to stack icons by dividing their size instead of multiplying them? I am looking to have my first icon be the same size as the font I am using, and the icon on top of it to be half the font size. Can this be achieved with Font Awesome or do I ...

The combination of Inline CSS and Bootstrap classes does not seem to be functioning properly

I'm new to web design and currently working on a website project. My concept involves hiding the #login-box when the user clicks on the login button, and displaying another element (.dashboard) in its place. Initially, I set the .dashboard class to ha ...

Implementing the Facebook share button: a guide

I am currently trying to replicate the Share button functionality found on a page like this. I would like users to be able to easily post a specific link to their news feed without having to deal with app permissions, along with the option to add some cu ...