Issue with centering content on Bootstrap 4 cards in vertical position

I'm facing an issue with vertical alignment of content within a card. I've gone through various resources in Bootstrap 4 for guidance, including:

Below is the code I've been working with:

<div class="col-sm-12 col-md-4">
    <div class="white-card item" data-mh="my-group-2">
        <div class="white-card-block h-100 justify-content-center">
             <div class="row">
                 <div class="left-side">
                     <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 27.02 20.97">
                      <defs>
                         <style>
                            .cls-1 {
                               fill: #ed8b00;
                               fill-rule: evenodd;
                             }
                         </style>
                       </defs>
                    <g id="Layer_1" data-name="Layer 1">
                        <g id="Guides">
                             <path class="cls-1" d="M27,4.1a1.67,1.67,0,0,0-.49-1.2L24.16.49a1.68,1.68,0,0,0-2.37,0L10.35,12.09,5.23,6.88a1.68,1.68,0,0,0-2.37,0L.49,9.29A1.67,1.67,0,0,0,0,10.49a1.7,1.7,0,0,0,.49,1.2L6.8,18.08l2.37,2.4a1.68,1.68,0,0,0,2.37,0l2.37-2.4L26.53,5.3A1.7,1.7,0,0,0,27,4.1Z" />
                         </g>
                       </g>
                    </svg>
                 </div>
              <div class="right-side">
                   <h4><strong>Easy Installation</strong></h4>
                   <p>Easy Installation on new or existing electric and gas tanks</p>
              </div>
         </div>
     </div>
</div> 

Here is the CSS I'm using for the card:

.white-card {
            margin: 15px 0;
            .white-card-block {
                .left-side {
                    display: inline-block;
                    width: 10%;
                    margin: 0 5%;
                }
                .right-side {
                    display: inline-block;
                    width: 80%;
                    p {
                        margin: 0;
                    }
                }
            }
        }

And here is a screenshot of the current appearance of my card: https://i.sstatic.net/ag61p.png

I've been struggling with this for a while now. Any assistance would be greatly appreciated. Thanks in advance! :)

Answer №1

I decided to simplify the structure by removing the unnecessary row div and replacing the class justify-content-center with two classes - d-flex align-items-center. Additionally, I applied these two classes to the left-side div as well for consistency.

To ensure the svg tag displays properly, I defined the width and height attributes.

Check out the example on JSFiddle

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
<div class="col-sm-12 col-md-4">
    <div class="white-card item" data-mh="my-group-2">
        <div class="white-card-block h-100 d-flex align-items-center">
                 <div class="left-side d-flex align-items-center">
                     <svg width="30" height="30" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 27.02 20.97">
                      <defs>
                         <style>
                            .cls-1 {
                               fill: #ed8b00;
                               fill-rule: evenodd;
                             }
                         </style>
                       </defs>
                    <g id="Layer_1" data-name="Layer 1">
                        <g id="Guides">
                             <path class="cls-1" d="M27,4.1a1.67,1.67,0,0,0-.49-1.2L24.16.49a1.68,1.68,0,0,0-2.37,0L10.35,12.09,5.23,6.88a1.68,1.68,0,0,0-2.37,0L.49,9.29A1.67,1.67,0,0,0,0,10.49a1.7,1.7,0,0,0,.49,1.2L6.8,18.08l2.37,2.4a1.68,1.68,0,0,0,2.37,0l2.37-2.4L26.53,5.3A1.7,1.7,0,0,0,27,4.1Z" />
                         </g>
                       </g>
                    </svg>
                 </div>
              <div class="right-side">
                   <h4><strong>Easy Installation</strong></h4>
                   <p>Easy Installation on new or existing electric and gas tanks</p>
              </div>
         </div>
     </div>
</div> 

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>

CSS

.white-card {
                margin: 15px 0;
                .white-card-block {
                    .left-side {
                        display: inline-block;
                        width: 10%;
                        margin: 0 5%;
                    }
                    .right-side {
                        display: inline-block;
                        width: 80%;
                        p {
                            margin: 0;
                        }
                    }
                }
            }

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

Utilize a JSP dynamic array to insert dynamic information into a database

I need to insert data into my database, extracted from a dynamically created table by the user with 2 columns (ID,Name) How can I retrieve each individual row that was inserted by the user and add it to the database? It's important to note that this ...

What is causing the action button in my MUI snackbar to occupy an additional line?

I'm currently learning how to use MUI and I'm struggling with a specific issue. The close button in my code is appearing on a separate line, but I want it to be on the same line as the word "again". I've tried experimenting with absolute pos ...

Best practices for refreshing the HTML5 offline application cache

My website utilizes offline caching, and I have set up the following event handler to manage updates: applicationCache.addEventListener('updateready', function () { if (window.applicationCache.status == window.applicationCach ...

Showcasing data from Django models in a tabular format

I am new to django and seeking assistance. I have developed a website but it's not fully operational yet. The model I created looks like this; from django.db import models class InductiveSensors(models.Model): Part_No = models.CharField(max_lengt ...

Tips for modifying a particular element within a class?

I am seeking guidance on how to modify a specific class attribute in CSS/JS/JQuery when hovering over a different element. Here is an example: <h1 class="result">Lorium</h1> <h1 class="result">Ipsum</h1> <h1 class="result">Do ...

What is the best way to incorporate multiple images using CSS styles?

Greetings! I am a newcomer to the world of CSS and I am currently utilizing a single image in my header, as shown below: #header { position: relative; background-image: url("../../images/header.jpg"); background-size: cover; background-pos ...

Guide to enabling picklist editing in the specified component within an Angular application

Currently utilizing the p-picklist component and looking to customize the displayed data in the target list span. You can find the source code at: Is there a way to enable editing of the product name within the target list? <p-pickList [source]=&quo ...

Applying a CSS border to a div that perfectly encloses a span, adjusting to the

My goal is to create a nested structure where a div contains a span element like this: ---------- |Sentence| ---------- ----------------- |It's a looooong| |sentence | ----------------- While it works well for short sentences, long ones end u ...

Implementing JavaScript validation to alter the background image

I encountered a small issue while working on my project. I was designing a form in HTML using JavaScript, and for the input fields, I decided to use a background image with padding on the left to enhance its appearance. Everything seemed fine until I ran i ...

Show me a way to use jQuery to show the number of images of a particular type that are on a

My webpage features 6 different images, including 4 of various balls such as basketball and baseball. One image is of a truck, while the last one is random. On the page, there is a form with two radio buttons allowing users to select which type of image c ...

Creating a blank grid using ng-repeat in angularJS

I'm attempting to create an empty grid using angularJS, but I've only been working with it for 2 days so I'm not very experienced. This is what I have come up with so far: <!doctype html> <html ng-app> <head> < ...

What are the steps to personalize Twitter Bootstrap with Less for changing the height of the Navbar?

I recently stumbled upon some interesting articles that explain how to customize various elements of Twitter Bootstrap using LESS. You can check out one of the articles here and find more information about Twitter Bootstrap here. However, I am still unsure ...

Ensuring that Bootstrap rows fill the entire height within a column

While working on a template with nested rows and columns in Bootstrap, the layout ended up looking like this: <div class="col-5"> <div class="row"> <div class="col-3 border border-secondary">Truck Number</div> ...

A neutral-toned backdrop that briefly shows up for a quick 7-second interlude during a background-image

Recently I created a website. On this website, there is a feature where 3 images change every 7 seconds for a total of 3 cycles. The code snippet used for this functionality is as follows: var swap; function run(interval, frames) { var int = 1; ...

Rearranging Twitter Bootstrap Grid Columns

Is it possible to rearrange columns in Bootstrap without using col-sm-pull-12/col-sm-push-12? I'm struggling to achieve the desired layout. Are there any alternative methods to accomplish this task? Check out this JSFiddle for reference. <div cla ...

Obtain the precise X and Y coordinates of a <li> element regardless of where the mouse is clicked using Typescript

I'm stuck and could really use some assistance! Hey there, I have a simple question but I seem to be missing a crucial element. Here's my fiddle where I can detect the clicked item but that's as far as I've gotten: http://jsfiddle.ne ...

How to use CSS to insert a line break after the fourth child in a

At this moment, the example displays an unordered list containing 8 list items. I am curious if there is a way to add a line break after the 4th li item using only CSS (no HTML or JavaScript). Perhaps something like: ul li:nth-child(4n):after { conte ...

Tips for placing modal box in the exact desired position upon loading

I've been searching for a solution on how to dynamically calculate the position of each image loaded in a Twitter modal box and place the box underneath a custom toolbar element I have created. The situation is depicted in the image. The height of the ...

Can anyone explain why my navbar text is not aligning in the center?

I am struggling to center the text in one of my two navbars. As a newcomer to both navbars and bootstrap, I am having difficulty figuring out why I can't achieve this. Should I be making changes on the bootstrap side or can it be fixed within the < ...

The arrangement and hue of elements using CSS styling

I am seeking to create a unique design with a predominantly gray background, accented by a smaller blue background within it. The design concept is illustrated below: <body> <div id= "background_1"> <div id= "background_2"> < ...