Issue with aligning Bootstrap 5 card tiles in a specific position

Can anyone guide me on the correct way to use the Bootstrap 5 card component to display an attached image in a card view?

Here is my code:

<!DOCTYPE html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>My </title>
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/main.css">

</head>
<body >

<!--Start main layout-->
<div class="wrapper">
    <div class="d-flex justify-content-center mt-5">
        <div class="">
            <div class="container">
            <div id="dynamic content" class="dynamic-content">
                <div class="row align-items-center animated flipInY slow delay-2s">
                    <div class="col-md-2 col-xs-12">
                        <div class="content" id="tile1">
                            <i class="fa fa-home fa-5x"></i>
                            <p>My Book</p>
                        </div>
                    </div>
                    <div class="col-md-2">
                        <div class="content" id="tile2">
                            <i class="fa fa-user fa-5x"></i>
                            <p>About</p>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="content" id="tile3">
                            <i class="fa fa-cogs fa-5x"></i>
                            <p>Services</p>
                        </div>
                    </div>
                    <div class="col-md-2">
                        <div class="content" id="tile4">
                            <i class="fa fa-comment fa-5x"></i>
                            <p>Feedback</p>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="content" id="tile5">
                            <i class="fa fa-briefcase fa-5x"></i>
                            <p>Portfolio</p>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="content" id="tile6">
                            <i class="fa fa-envelope fa-5x"></i>
                            <p>Contact</p>
                        </div>
                    </div>
                    <div class="col-md-5">
                        <div class="content" id="tile7">
                            <i class="fa fa-quote-right fa-5x"></i>
                            <p>Free Quote</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        </div>
    </div>
</div>
<!--End of main layout-->
</body>

<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="js/bootstrap.bundle.min.js"></script>
<script src="js/popper.min.js" ></script>
<script src="js/bootstrap.min.js" ></script>
</html>

Thankshttps://i.sstatic.net/JY4Y0.png

Answer №1

Implement Bootstrap 5 grid system

To create rows, use the class .row, and for columns, use the class .col.

According to Bootstrap 5's official documentation: Each row has 12 template columns that can be utilized to arrange elements in any desired configuration.

I have used the .col-3 class four times to create four primary "sections." These four instances of .col-3 collectively occupy a maximum of 12 columns per row (i.e. 3 * 4 = 12). Within these four main "sections," there are multiple instances of .row and .col.

Choosing the appropriate .col classes

For creating layouts, use .col-5 and .col-11 in the following manner:

  • Use two instances of .col-5 within the same .row if you wish to display two boxes side by side.
  • Use one instance of .col-11 within the same .row for displaying one box in a row.

Reasoning behind the selection of .col-5 and .col-11

The choice of .col-5 over .col-6 becomes evident when positioning two columns within the same row. Using .col-6 would eliminate the spacing between the columns, as each column occupies 6 units, summing up to the maximum allowable 12 units. Conversely, .col-5 leaves room for spacing, with 5 units being occupied by each column, resulting in a total of 10 units.

Using two instances of .col-5 within the same .row:


Using two instances of .col-6 within the same .row:

When utilizing .col-5 twice in a single .row (as depicted in the first image), the columns are automatically spaced apart.

Opt for .col-11 for aesthetic purposes. Placing .col-11 alongside a row containing two .col-5 columns ensures equal width for both rows. This parity in width can be further emphasized by including .d-flex .justify-content-around in all relevant rows. More details can be found in the documentation.

Additional Recommendations

To horizontally align content, utilize the class .d-flex .justify-content-center, and for vertical alignment, use .d-flex .align-items-center. These classes can be instrumental in centering content, such as Font Awesome icons and titles, horizontally and vertically simultaneously within the designated boxes.

For text alignment within boxes, encompass the Font Awesome icon and the title with

<div class='text-center'>...</div>
, ensuring that the text is centered.

At the end of the HTML document, add an image and apply CSS modifications including:

  • position: absolute; and z-index: -100; for background placement,
  • width: 100vw; and height: 100vh; for full-screen display, and
  • filter: blur(50px); for adding a blur effect.

The Code Snippet

body {
  margin: 0;
  padding: 0;
}

#wrapper {
  width: 100vw;
  height: 100vh;
}

#inner_wrapper {
  margin-top: -15vh;
  margin-left: 10%;
}

.row {
  margin: 0;
  width: 100%;
  height: 15vh;
  /* Set this value the same as the margin-top for the #inner_wrapper. */
}

.col-5,
.col-11 {
  border-radius: 1vw;
}

.fa-home {
  font-size: 2.5vw;
  color: white;
}

#white {
  font-size: 1vw;
  color: white;
}

...
<!DOCTYPE html>
<html lang='en'>

<head>
  ...
</head>

<body>

  ...
  
</body>

</html>

Answer №2

Unique Bootstrap Card Solution

crafted with minimal CSS

The Structure

#groups {
  min-width: 1140px;
}

body {
  background-image: url(https://i.imgur.com/W3BxqV7.png);
}

.item {
  height: 100px;
  margin: 5px;
}

.group.col {
  margin: 10px;
}
<html lang="en">
...
</html>

With Custom Styling

Utilizing JavaScript for automation, but adaptable with CSS

const colors = ["#2C78E2", "#43BB88", "#E27B2D"...;
document.querySelectorAll('.item').forEach(function(e, i) {
  e.style.backgroundColor = colors[i];
})
#groups {
  min-width: 1140px;
}

body {
  background-image: url(https://i.imgur.com/W3BxqV7.png);
}

.item {
  height: 100px;
  margin: 5px;
}

.group.col {
  margin: 10px;
}
<html lang="en">
...
</html>

Enhanced with Content

const colors = ["#2C78E2", "#43BB88", "#E27B2D"...;
document.querySelectorAll('.item').forEach(function(e, i) {
  e.style.backgroundColor = colors[i];
})
#groups {
  min-width: 1140px;
}

body {
  background-image: url(https://i.imgur.com/W3BxqV7.png);
}

.item {
  height: 100px;
  margin: 5px;
}

.group.col {
  margin: 10px;
}
<html lang="en">
...
</html>

Optimized for Responsiveness

const colors = ["#2C78E2", "#43BB88", "#E27B2D"...;
document.querySelectorAll('.item').forEach(function(e, i) {
  e.style.backgroundColor = colors[i];
})
body {
  background-image: url(https://i.imgur.com/W3BxqV7.png);
}

.item {
  height: 100px;
  margin: 5px;
}

.group.col {
  margin: 10px;
}
<html lang="en">
...
</html>

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

AngularJS provides a convenient way to vertically populate data cells in a table

Looking to vertically populate data cells with an array in this HTML table. Below is a basic HTML table structure: <table> <th>Name</th> <th>Value</th> </table> Current table data: Name Value X Y Desired output: ...

Boxes not occupying entire vertical space

My structure is unique, like a 9-box with div elements: <div class="NBWrapper"> <div class="NBTopRow"> <div class="NBLeft" /> <div class="NBRight" /> <div class="NBMiddle" /> </div> & ...

Insufficient width of images in the bootstrap carousel

Is there a different solution to this problem that hasn't been mentioned in the other posts? I've tried all the top solutions from those posts, but my issue still remains. In particular, the "example" code and "Stock" bootstrap carousel appear t ...

The HTML required attribute seems to be ineffective when using AJAX for form submission

Having trouble with HTML required attribute when using AJAX submission I have set the input field in a model Form to require attribute, but it doesn't seem to work with ajax. <div class="modal fade hide" id="ajax-book-model" a ...

Mixing together an array of colors, experimenting with adding a touch of transparency

Here is my first question, diving right in. I recently created a canvas in HTML and followed a tutorial to generate random floating circles that interact with the mouse position......if you want to check it out, click here. The issue I'm facing now ...

Creating a unique carousel design using only CSS in Bootstrap

Trying to create a CSS effect to enhance Bootstrap, I noticed that it only works correctly when clicking the right arrow. Whenever I click the left one, nothing happens. I'm not sure where I made a mistake, can anyone help me spot it? Thanks in advanc ...

Having difficulties setting up the bootstrap-table with Rails 6, webpack, and Bootstrap 5. Despite my efforts, it keeps defaulting to Bootstrap 4 version on

My Recent Project In my latest project, I successfully integrated Bootstrap 5. However, I encountered an issue when trying to install bootstrap-table using the command: yarn add bootstrap-table In my application.js file, I included the following: import ...

Adjusting the gutter size for specific components in Bootstrap 4 using a mixin

How can I adjust the spacing between specific elements using mixins in my code? I've searched through numerous tutorials, but I haven't found the solution I'm seeking. Here is the code snippet I'm working with: <div class="row" id= ...

Is it permissible to have <ul> tags within an H1 element?

I am curious about whether adding a list inside an H1 heading could cause any issues: <h1> <ul> <li><a href="...">some link</a></li> <li><a href="...">another link</a></li> <li>curre ...

Navigating the Foundation Topbar - Should I Toggle?

Is there a simpler way to achieve the navigation I desire, similar to the switcher for uikit? Instead of using data-toggler on each tag in my top bar, is there an easier method where I can click links in my top bar to display different content without go ...

My node.js code is not producing the expected result. Can anyone point out where I may be going wrong?

I've been working on a BMI calculator where I input two numbers, they get calculated on my server, and then the answer is displayed. However, I'm having trouble receiving the output. When I click submit, instead of getting the answer, I see a lis ...

Is there a way to redirect the user to a different page without refreshing the page during navigation?

Utilizing javascript, ajax, and jquery to dynamically load content from PHP files without refreshing the page has been a successful venture. However, I am facing a challenge in creating a hyperlink within one of the loaded contents that redirects the user ...

Fast method or tool for generating a detailed CSS element list from deeply nested elements

I have been using Chrome dev tools to work on a code base that was not created by me. There are numerous deeply nested elements scattered throughout the code. I find myself having to manually search through the HTML structure in order to select them with ...

Creating interactive comments in Vue 3 using dynamic rendering

Is there a way to properly display a dynamic comment in Vue 3? I attempted using v-html, but it's not working as expected in my scenario. Here is the example: https://i.sstatic.net/ddX39.png <template> <!-- Method 1: not displaying correctl ...

Struggling with React Js and need some assistance?

I'm completely new to React Js and encountering issues with my code. Here's what I have: Here is the content of my script file named Main.jsx. This file gets compiled by React, and the output is stored in main.js under the 'dist' folde ...

Several DIV elements lined up side by side

I've been working on a program that retrieves data from a database, lists some of the data when a button is clicked within the same div, and then creates new divs with buttons that have onclick events until it reaches a certain maximum value. To keep ...

Display a sneak peek on a separate tab

I have an editor on my website where users can input and edit their own HTML code. Instead of saving this to a database, I want to display the current user's HTML code in a new window using JavaScript. How can I achieve this without storing the code p ...

What are some ways I can troubleshoot my contact form?

As someone new to web design, I recently completed my very first site using a combination of HTML, CSS, and a touch of JavaScript. I managed to create a small contact form within the site, but now I'm wondering if there's a way to make it functio ...

The table is hidden and the buttons are unresponsive when inserted using jQuery

Exploring blueimp's jQuery-File-Upload Demo has been occupying my time recently. After studying it for several days, I feel like I've gained a solid grasp of how it functions. However, as someone with limited experience in web development, there ...

Is there a way to showcase the output of the <div id="height"> on the height of the rectangle?

My Current Project Currently, I am in the process of developing a picture framing calculator using a combination of HTML, CSS, and JavaScript. Functionality of the Calculator For this calculator, users will input values such as: Frame Width (wf): 16 ...