What is the best way to perfectly align cards both horizontally and vertically on the entire page, ensuring the layout remains consistent on mobile devices as well?

When viewed on larger screens, such as monitors, the layout functions perfectly. However, on smaller screens like mobile phones, some cards may get cut off.

On larger screens, the cards are displayed in a single row and will adapt to a new line if the screen size decreases:

https://i.sstatic.net/pHEXR.png https://i.sstatic.net/aXXS4.png

On smaller screens, the cards are stacked vertically as they should be. However, some cards become unreachable and are cut off, as shown in the image below:

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

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" name="viewport" content="height=device-height width=device-width, shrink-to-fit=no">
        <script src="scripts/jquery.js"></script>
        <script src="scripts/jquery_ui.js"></script>
        <script src="scripts/bootstrap.js"></script>
        <link rel="stylesheet" href="styles/bootstrap.css">
        <title>Overview</title>
    </head>
    <body>
        <div class="d-flex flex-wrap justify-content-center align-content-center align-items-center vw-100 vh-100">
            <div class="card m-3">
                <div class="card-header text-center">1</div>
                <div class="card-body">
                    <div class="card-text">Text Text Text Text Text Text</div>
                    <div class="card-text">Text Text Text Text Text Text</div>
                    <div class="card-text">Text Text Text Text Text Text</div>
                </div>
                <div class="card-footer text-center">
                    <button type="button" class="btn btn-dark">Text</button>
                </div>
            </div>
            <!-- More card elements here -->
        </div>
    </body>
</html>

Answer №1

To remove the vh-100 class from your first div, you can either delete it entirely or use it specifically for the screens where it is needed such as vh-md-100, vh-lg-100, vh-xl-100.

<div class="d-flex flex-wrap justify-content-center align-content-center align-items-center vw-100 vh-md-100 vh-lg-100 vh-xl-100">

Check out this live example

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

Styling your tables with custom CSS in Bootstrap 4

Looking to design a unique CSS for a Bootstrap 4 table without impacting other standard tables. Can anyone provide the specific CSS code for customizing this table and setting it for all elements? <table class="table table-responsive table-bordered t ...

Removing the css class when an element loses focus

In order to improve user experience on my web page, I have implemented a validation check on a form before submitting it back to the server. The validation process is successful and applies a custom CSS class called ErrorControl to input fields when necess ...

Managing multiple sets of data in a structured form similar to an array

How Do I Send Form Data as an Array? Take a look at the code snippet below. I'm having trouble setting the index in product_attribute['index must be here']['key'] <tr v-for="index in attributes"> <td class="text-left ...

Tips for creating a curved shape using fabric.js

I am encountering an issue while trying to draw an arc using a circle with a start and end angle in my code. Here is the snippet I am working with: var circle = new fabric.Circle({ radius: 30, left: 20, top: 20, fill: " ...

Positioning a group of hyperlinks to the right side

I'm encountering an issue aligning a list of links to the right side. The problem arises when the parent div width is increased beyond a certain point. For instance, with width=700px, everything looks fine: However, with width=800px, it appears like ...

Display a PNG image in React with a sleek and stylish transparent background

Whenever I try to set an image with the following CSS properties: width: 100%; height: 100%; background: url(example.com/image.png) no-repeat; background-size: cover; The background appears as white. Is there a way to display it with grey ...

Obtain data from various selection lists that share a common identifier

I have three select boxes with the same option IDs but different values. These select boxes will store information in three columns called id, nameuz, nameru. I would like it so that when I select an option from one select box, the other select boxes also ...

the intricacies of resizing a dijit dialog

My dialog is defined as shown below: <div data-dojo-type="dijit/Dialog" id="DetailDialog" class="dijitDialog" ... I have loaded a grid inside the dialog with 10 columns. var dialog = dijit.byId("DetailDialog"); dialog.set("content", this.Details); d ...

Why do CSS media queries stop working at exactly 5 distinct resolution sizes? This seems odd

Just completed my first JavaScript project, a 3D website using three.js. However, right before publishing, I realized that the dimensions and contents were not optimized for viewing on browsers other than 1920x1080. So, I delved into setting DevicePixelRat ...

What is the best way in jQuery to display a particular div with a unique id when a link is clicked?

I have a div with the following structure: <article id="#pippo">blablabla</article> which I have hidden using jQuery $('article').hide(); Now, I want to create a link menu that displays a specific article id when it's clicked ...

jQuery Mobile - Implementing Persistent Toolbars along with a custom back button functionality

UPDATE Here is a fiddle of the problem: https://jsfiddle.net/9k449qs2/ - attempt to select the header using your picker, but every time you click it will select the whole page instead. I am currently working on a project that includes a persistent header ...

Leveraging GitHub's syntax highlighting feature

On GitHub, what type of syntax highlighting is utilized for HTML, CSS, JavaScript, and C# when viewing source code files and is it accessible for public use? It functions both on the page and when embedded onto a page (from a Gist), as shown below: <s ...

What is the best way to style my text fields in Django using Bootstrap?

In my form class, I have lines that look like this: class ReportForm(forms.ModelForm): diagnosis = forms.CharField(widget=forms.Textarea(attrs={'cols': 200, 'rows': 3})) class Meta: model = Report Then, when I render the form ...

Tips for switching images in a grid using jQuery

I have implemented an image grid using flexbox on a website I am developing. The grid consists of 8 boxes, and my goal is to randomly select one box every 2 seconds and assign it one of 12 random images. My strategy involves creating an array containing UR ...

Guide on redirecting to an HTML page on a local computer

Recently, I created an HTML page named A.html on my local computer which consists of 2 text fields and a button. I made a host entry to access the file via localhost. Upon clicking the button on A.html, it redirects me to a corporate login page where I ne ...

Implementing a pre-defined value for ajax in ajax programming for beginners

I'm looking for guidance on setting up a hardcoded value for the OnSuccess parameter. The code I'm referencing is not my own, but I believe it may be related to Ajax. I'm a bit confused about it. Specifically, I need to focus on the OnSucce ...

Design an HTML button/label with text and a starting width of zero

I'm attempting to design HTML buttons and labels with text that initially have zero width. Once inserted, they should smoothly transition to a visible state. I've tried adjusting the initial width and min-width style properties without success. ...

Why does the div inside the tbody element get automatically shifted outside of the tbody during rendering?

Below is a snippet of my code: <body> <table> <tbody> <div>test</div> </tbody> </table> </body> Upon executing the code mentioned above, it transformed automatically in ...

What are the best methods for utilizing rating stars in PHP?

Currently, I am incorporating the star rating system from Rating Stars. I am working on creating a PHP table and dynamically populating it with records. In this table, there will be a column dedicated to displaying these stars. Each record is saved as a n ...

PHP and Oracle: Mastering the art of CRUD operations

I'm currently working on a form to update user information stored in an Oracle database. For some reason, the updates are not going through correctly even though I have the form printing out the SQL being submitted to Oracle and everything seems to ch ...