How to Align Horizontal Scrollable Cards in Bootstrap 4

Having trouble centering a Single Row of Horizontal Scrolling Cards.

I've tried: a) the mx-auto class b) using text-align: center

Nothing seems to be working and there's a lot of space on the right side in desktop view.

Interestingly, the scrolling div is perfectly centered on mobile screens.

Any advice from experts on the right approach would be highly appreciated.

https://i.sstatic.net/kuhrI.png

https://i.sstatic.net/xBErW.png

<style>
      
img {
  border-radius: 50%;
 -webkit-filter: grayscale(100%); /* Safari 6.0 - 9.0 */
  filter: grayscale(100%);
  margin-top: 5px;
}

.forlabel {
    margin-top:-12px;
}
.forlabeldiv {
    border:solid; 
    border-width:1px; 
    border-radius:5px;  
    <!-- margin-left:5px; 
    margin-right:5px; 
    margin-bottom:15px;-->
    margin: 0,auto;
    width:100%;
    text-align:center;
}
.forlabelspan { 
        color: #0275d8;
        background:white;
        font-size:14px;
        font-weight:800;
}       
.btn {
    width:30%;
    text-align: center
    margin-bottom:5px   
    }
.card-block {
    min-height: 25vh;
    margin-bottom:15px;
}   
    
.profile, .card {
    background:#ced7df!important;
    text-align:center;
    }
    
.master {
    text-align:center;
    margin: 0,auto;
    }
</style>
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Single Row Horizontal Scrolling Cards</title>
  <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0">   

    
    
</head> 
<body>
<!----------------------xxxxxxx---------------------------->
<h2>Single Row Horizontal Scrolling Cards</h2>  
<div class="container-fluid p-3 m-3 master" >   
  <div class="container forlabeldiv row  max-auto" >    
     <label for="input1" class="col-sm-2 forlabel" >
       <span class=" forlabelspan">Expert Panel</span> 
    </label> 
    
    <div class="row flex-nowrap overflow-auto ">

       <div class="col-12 col-lg-6" >
            <div class="card card-block profile" >      
            <img class="mx-auto" src="https://via.placeholder.com/100/09f/fff.png" width="100" height="100" >
             First Name Last Name<br>
             Title of Person<br>
             Credentials of Person<br>
            <a href="#" class="btn btn-danger mx-auto">BOOK</a> 
           </div>
        </div>     
          <div class="col-12 col-lg-6">
            <div class="card card-block  " style="text-align: center" >     
            <img class="mx-auto" src="https://via.placeholder.com/150" width="100" height="100" >
             First Name Last Name<br>
             Title of Person<br>
             Credentials of Person<br>
            <a href="#" class="btn btn-danger mx-auto">BOOK</a> 
           </div>
        </div>    
        
        ... and so on
        
        </div> <!--*** end of row flex  *** -->
       </div> <!--*** end of label div  *** -->
    </div> <!--*** end of container-flex -->
    
<!----------------------xxxxxxx---------------------------->    
</body> 

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.3/jquery.min.js" integrity="sha512-STof4xm1wgkfm7heWqFJVn58Hm3EtS31XFaagaa8VMReCXAkQnJZ+jEy8PCC/iT18dFy95WcExNHFTqLyp72eQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>  
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1c6c736c6c796e32766f5c2d322d2a322d">[email protected]</a>/dist/umd/popper.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c1a3aeaeb5b2b5b3a0b181f5eff7eff3">[email protected]</a>/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="76141919020502041706364258405844">[email protected]</a>/dist/js/bootstrap.bundle.min.js"></script>
    

Answer №1

Implemented a CSS style to add padding to the body tag, resulting in the centering of the div:

body { padding:50px; }    

Although I'm not entirely sure of the technical details, it successfully resolved the problem I was facing!

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

Is there a way to modify the title of a website upon entering the webpage and then updating it when moving to a new page?

I'm encountering an issue with changing the website title during two specific processes. Upon entering a webpage, the title is modified using the following code: <script type="text/javascript"> $(document).ready(function() { docum ...

Guide on transferring an HTML template to a React component using props

I've created a React popup window component that accepts templates via props. Check out this example of how the popup is used: popup = ( <div> <Popup text='This is a popup' popupEl={ popupEl } /> < ...

What is the best method to determine offsetTop in relation to the parent element instead of the top of

I have a straightforward inquiry: How can one determine the offsetTop of a child element in relation to its parent element rather than the top of the window? The definition of offsetTop indicates that it should give the distance by which a child element i ...

Struggling to understand why my React Component is failing to render properly

Could there be an issue with how I imported react or am I simply overlooking something small? Any feedback would be greatly appreciated. As a beginner in programming, I may be missing a simple solution that I'm not experienced enough to identify. Than ...

Using both text and image sprites in a horizontal menu list on a UL element

I am attempting to create a horizontal menu using image sprites and text, but have been unsuccessful so far. Although I have an idea of what I want it to look like, my CSS is not achieving the desired result. This is what my current CSS looks like: < ...

The chosen options are not appearing. Could this be a problem related to AngularJS?

I am working on setting up a dropdown menu in HTML that includes only the AngularJS tag. This dropdown menu will be used to populate another AngularJS dropdown menu. Below is the code for the first dropdown menu: <select class="form-control" ng-model=" ...

"Printed documents fail to display underlined text using Bootstrap styling

Why do the codes show underlines on the webpage but not in the browser's print? This code is from the printOrder.blade.php file: <!DOCTYPE html> <html dir="ltr" lang="en"> <head> <meta charset="UTF-8&qu ...

What is the best way for me to automatically square a number by simply clicking a button?

How do I create a functionality that multiplies a number by itself when a specific button is clicked? I want this operation to only occur when the equals button is pressed. I have been attempting to set this up for over an hour without success. My current ...

Merge a dropdown menu with an alphabetically arranged list that is interactive with clickable options

I am still learning HTML and Javascript but I'm doing my best. Currently, I am facing a challenge where I need to create a button that, when clicked, opens a dropdown menu containing a table of data. The user should then be able to select a number fr ...

show an HTML webpage within a <div> container using AJAX technology

I am trying to include an HTML page named Introduction.html (located in the same folder as x.html) within div1. However, it does not seem to be loading properly. Below is a snippet of the code from x.html x.html <!DOCTYPE html> <h ...

Styling text and images with Bootstrap

Currently, I'm utilizing bootstrap to structure a row with 2 div elements. The first div contains an image while the second div holds text content. The challenge I am facing is aligning the text to the edge of the image. However, since the image does ...

Using jQuery to enable scrolling and dynamically changing classes

I'm currently working on enhancing my website with a feature that changes the opacity of the first section to 0.4 when a user scrolls more than 400 pixels down the page. I attempted the following code without success: if($("html, body").offset().top ...

Combining jQuery form validation with a PHP script on a single webpage

After implementing jQuery form validation and redirecting using the function btn_onclick() { window.location.href = "http://localhost/loginprivate.php";} from index.php to loginprivate.php, my web app's PHP script is not being executed. The user is re ...

Tips for transforming an SQL Server query into JSON format

I need to construct a table in a view utilizing the output of this particular SQL Query SELECT f.empresaid, e.fantasia AS Company, f.filialid, f.fantasia AS Branch, u.consultorid ...

I cannot understand why I keep receiving <input type="email" value="required"> when all I want is <input type="email" value="" required>

Currently, I am working with PHP code and here is my complete PHP code: echo "<input type=\"email\" class=\"profil_input_text form-control\" name=\"user_email\" pattern=\"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(& ...

Challenges arise with the Boostrap grid system, overflow scroll functionality, and responsive design when incorporating specific heights (vh) in elements

Attempting to implement a two-column layout using Bootstrap 4 that incorporates an overflow scroll feature when the height of a parent container is specified. You can view the fiddle here: https://jsfiddle.net/zeropsi/g19kzpsh/ The challenge I'm fac ...

How come outerHTML retrieves <!-- --> comments?

I came across a jsfiddle link that showcases the collection of outerHTML for elements with a class='active'. Surprisingly, even when certain parts of the HTML are commented out like this: <!-- <div>'Some inner text'</d ...

Creating eight equal sections within HTML <div> elements using Bootstrap

I am brand new to Angular. I need to design something like this: https://i.sstatic.net/Zcb9i.png However, I'm struggling to find the right solution. Here is what I have so far: https://i.sstatic.net/7hsrk.png. Having been a backend developer, I&ap ...

The use of Material-UI collapse animation in a table results in the insertion of div elements, triggering a validateDOMNesting warning

Having a data-filled table, I am looking to implement smooth transitions when adding or deleting an item. This is a ReactJS project utilizing Material-UI. The desired effect is similar to the one demonstrated in their example. While they use a List compon ...

The process of overriding CSS applied through JavaScript

I am using a third-party multi-select dropdown. Similar to Select2, the multi-select dropdown is created using JQuery with select2.min.js and the width of the dropdown is automatically calculated. Is there any way to apply static width to it, as I believe ...