Centering Text and Icon in a Bootstrap Box

I am struggling to center the text and icons within a box. I want them to be perfectly centered, like this:

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

I've attempted the following: adding inline styles of align-content: center and justify-content: center to the div tag for row, but it hasn't worked. Any assistance or guidance would be greatly appreciated. You can view my current setup on jsfiddle by clicking the link below. Currently, all content is aligned to the left.

https://jsfiddle.net/silosc/76ktyveu/4/

<div class="row" style="width:100%">
    <div class="report-card-i report-card-i-height">
        <h3 class="m-l-35 p-t-25 p-b-10">Stats</h3>
        <div class="fa-orange m-t-10 m-b-15">
            <div class="row">
                <div class="col-sm-3 col-xs-3">
                    <i class="fa fa-star m-r-15">Stat1</i>
                </div>

                <div class="col-sm-2 col-xs-3">
                    <i class="fa fa-angle-right"></i>
                </div>
            </div>
            <br />
            <div class="row">
                <div class="col-sm-3 col-xs-3">
                    <i class="fa fa-star m-r-15">Stat2</i>
                </div>

                <div class="col-sm-2 col-xs-3">
                    <i class="fa fa-angle-right"></i>
                </div>
            </div>
            <br />
            <div class="row">
                <div class="col-sm-3 col-xs-3">
                    <i class="fa fa-star m-r-15">Stat3</i>
                </div>

                <div class="col-sm-2 col-xs-3">
                    <i class="fa fa-angle-right"></i>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
   .report-card-i{
    background: orange;
    box-shadow: 2px 2px 10px 4px rgba(0, 0, 0, 0.2);
    position: relative;
    margin-top: 30px;
}

 .report-card-i-height {
    min-height: 280px;
    height: auto;
    width: 100%;
        }

.report-name {
    font-family: Questrial;
    font-weight: bold;
    color: #f0522f !important;
        }
</style>

Answer №1

Bootstrap can simplify your layout with the text-left class. Make sure to adjust your margin and padding classes correctly, using mr-1 to mr-5 for margins and the same format for paddings.

.report-card-i {
  background: orange;
  box-shadow: 2px 2px 10px 4px rgba(0, 0, 0, 0.2);
  position: relative;
  margin-top: 30px;
}

.report-card-i-height {
  min-height: 280px;
  height: auto;
  width: 100%;
}

.report-name {
  font-family: Questrial;
  font-weight: bold;
  color: #f0522f !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="row" style="width:100%">
  <div class="report-card-i report-card-i-height">
    <h3 class="ml-5 pt-5 pb-2">Stats</h3>
    <div class="fa-orange mt-5 mb-5">
      <div class="row">
        <div class="col-sm-3 col-xs-3 text-center">
          <i class="fa fa-star">Stat1</i>
        </div>

        <div class="col-sm-2 col-xs-3">
          <i class="fa fa-angle-right"></i>
        </div>
      </div>
      <br />
      <div class="row">
        <div class="col-sm-3 col-xs-3 text-center">
          <i class="fa fa-star m-r-15">Stat2</i>
        </div>

        <div class="col-sm-2 col-xs-3">
          <i class="fa fa-angle-right"></i>
        </div>
      </div>
      <br />
      <div class="row">
        <div class="col-sm-3 col-xs-3 text-center">
          <i class="fa fa-star m-r-15">Stat3</i>
        </div>

        <div class="col-sm-2 col-xs-3">
          <i class="fa fa-angle-right"></i>
        </div>
      </div>
    </div>
  </div>
</div>

Answer №2

For a helpful tip, consider this: .icon { margin-left: 50%; transform: translateX(-50%); }, to add some space between the icon and text, you may use: .icon-star:before { padding-right: 20px; }

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

Unique CSS Styles for Border Radius

Is there a way to achieve rounded corners on only the top left and top right, but not on the bottom two corners of a div using a specific value for -webkit-border-radius? ...

Adjusting the empty image source in Vue.js that was generated dynamically

Currently experimenting with Vue.js and integrating a 3rd party API. Successfully fetched the JSON data and displayed it on my html, but encountering issues with missing images. As some images are absent from the JSON file, I've saved them locally on ...

The jQuery method .find() is unable to locate the <option> tag and behavior unpredictably

Currently, I am working on a webpage that features a table with filtering capabilities using jQuery. The filtering functionality is achieved through a Bootstrap 4 dropdown menu where each option is assigned a specific value: <select id="inputState& ...

Ways to create a sequential appearance of elements through CSS animations

Can you help me achieve a wave effect for elements appearing one by one using CSS animation (jQuery)? Currently, all the elements show up at once and I want to create a wave-like motion. Any assistance would be greatly appreciated. $(window ...

Submitting an HTML form to trigger a PHP function through AJAX

I am currently working on a task that involves POSTing an email address entered in an HTML form to a PHP script for storage in a database. The script should also handle error messages if the user inputs an invalid email address. I want to make this process ...

Adding a class to an img tag with TinyMCE

Currently, I am utilizing the TinyMCE editor as a standalone editor in my content management system (CMS). Within the CMS, there is an automatic setting that adds a curved border to any image tags within the cms div ID. In certain cases, I require the op ...

What is the code to automatically change the selected input radio button every 3 seconds?

I am attempting to cycle between different input radio buttons being checked every 3 seconds in my Next.js project. The switching works from case0 to case1 and case1 to case2, but not from case2 back to case0. My React and Next.js knowledge is at an inte ...

Enhance React-D3-Graph ViewBox

I have a dataset named actors storing nodes and links called scratch. The structure is as follows... { "nodes": [ { "id": "Guardians of the Galaxy" }, { "id": "Chris Pratt" }, ...

Trigger a JavaScript event when attempting to input the maximum number of characters

I am currently facing a challenge with implementing a tooltip on a text area that has a maximum character limit of 500. The tooltip should only appear when the user reaches the maximum character count and attempts to input more characters. My previous appr ...

Modifying the style of the HTML placeholder tag

One approach I am taking involves utilizing a placeholder element within my search box input: <input id="searchBarTextbox" type="search" class="k-textbox" placeholder="Search For..." /> My challenge now is to enhance the aesthetics of the placehold ...

I'm trying to create a transparent v-card, but for some reason it's not turning out the way I want

How can I make the v-card transparent while keeping its content opaque using CSS? card.vue <v-card class="cardColor"> <v-card-text> TEXT </v-card-text> <v-card-actions> <v-btn color="prima ...

Send data from a PHP form with various input types using JavaScript and AJAX

I need to submit a form with various fields, including multiples checkboxes selection and some hidden input fields via AJAX and then replace the HTML content with the response. I decided to use JavaScript/AJAX for this process, but did I make any mistakes? ...

Exploring the Images directory

I hate to admit it, but I'm really struggling with this question. It's frustrating and I've searched everywhere for an answer. Currently, I'm using WAMP on Localhost with PHPstorm. The issue I'm facing is accessing the images di ...

How come I am unable to vertically align my elements with bootstrap?

Currently, I am in the process of developing a windsurfing website. Despite utilizing classes such as justify-content-center, align-items-center, and text-center, I am facing an issue where the h1 and h2 elements remain positioned at the top and are not ve ...

Exploration of search box with highlighted fields

Seeking assistance to enhance the highlighting feature after entering a letter in the search box. Here is the current code snippet: <!DOCTYPE html> <html> <head> <script type="text/javascript" src="javascripts/jquery-1.11.0.min.js"&g ...

Determining the dimensions of form elements in an inline layout using Bootstrap 3.1

Currently in the process of upgrading my application from version 3.0 to 3.1. The application is still in its initial phase, resembling more of a prototype with only a few pages created. Therefore, I didn't anticipate encountering many issues during t ...

Maps from Here will only show if they are visible from the beginning

I am attempting to integrate Here Maps into my web application. The map should only be displayed once the user has clicked on a button or link to expand a collapsible panel made with Bootstrap. When I place the div containing the map outside of the collap ...

Leverage CSS variables to dynamically create class names within SCSS

Can CSS variables be used to generate class names? I am incorporating SCSS in an Angular project and I am looking to base my class names on the @input color component property. I have stored the input in a CSS variable called --color-variable to utiliz ...

There seems to be a problem in Safari with the use of `:after` and `:before` when applying

I've been facing an issue with Safari not properly box-sizing after the "load" function. It functions perfectly on Chrome, Firefox, and IE, but not on Safari. You can view the specific page with the problem here: goo.gl/HKJy4g The problem lies with ...

Populate a string with HTML elements

I need help loading a string into UIwebview. The text is plain coming from the database. I want the webview to display the text in bold. How can I add an HTML <b> tag or any other tag to format this simple text sourced from the database? ...