How to Right Align Text in a Bootstrap Table

Exploring Bootstrap, I challenged myself to create a table without the usual table tags, using only the grid system. While I managed to make it look decent, I'm struggling to align the numbers to the right. Here's a JSFiddle link to what I've come up with. Any guidance or suggestions would be greatly appreciated.

https://jsfiddle.net/silosc/9jbd1rpw/2/

<div class="container-xl">
  <div class="report-card-weekly-report">
    <div class="CompanyName">
      <h1>Weekly Summary for John's Groceries</h1>
      <h4> Week Ending: 01/20/2010</h4>
    </div>

    <br />
    <div class="row">
      <div class="col-sm-2">
      </div>
      <div class="col-sm-2">
        <p>Number of Sales</p>
      </div>
      <div class="col-sm-2">
        <p>Total earnings</p>
      </div>
      <div class="col-sm-2">
        <p>Taxes charged</p>
      </div>
      <div class="col-sm-2">
        <p>Refunds</p>
      </div>
      <div class="col-sm-2">
        <p>Deliveries</p>
      </div>
    </div>
    <div class="row">
      <div class="col-sm-12">
        <h2>Total numbers</h2>
      </div>
    </div>
    <div class="row">
      <div class="col-sm-2">
        <p>Numbers for the week</p>
      </div>
      <div class="col-sm-2">
        21,922
      </div>
      <div class="col-sm-2">
        $0.00
      </div>
      <div class="col-sm-2">
        $304,431.37
      </div>
      <div class="col-sm-2">
        $0.00
      </div>
      <div class="col-sm-2">
        $0.00
      </div>
    </div>
  </div>
</div>


<style>
  .CompanyName {
    text-align: center;
  }
  
  h2 {
    color: orangered;
    margin-left: 15px;
  }
  
  p {
    font-weight: bold;
    font-size: 15px;
    margin-left: 15px;
  }
  
  p1 {
    text-align: right;
  }
</style>

Answer №1

To align your text to the right using bootstrap, you can utilize the text-right property. Here's a snippet of code to demonstrate how it can be implemented:

  <div class="col-sm-2 text-right">
       21,922
  </div>

Similarly, if you want to align the text to the left, you can use the text-left property.

Answer №2

You have the option to utilize the text-right class from Bootstrap:

<div class="container-xl">
  <div class="report-card-weekly-report">
    <div class="CompanyName">
      <h1>Weekly Summary for John's Groceries</h1>
      <h4> Week Ending: 01/20/2010</h4>
    </div>

    <br />
    <div class="row">
      <div class="col-sm-2">
      </div>
      <div class="col-sm-2">
        <p>Number of Sales</p>
      </div>
      <div class="col-sm-2">
        <p>Total earnings</p>
      </div>
      <div class="col-sm-2">
        <p>Taxes charged</p>
      </div>
      <div class="col-sm-2">
        <p>Refunds</p>
      </div>
      <div class="col-sm-2">
        <p>Deliveries</p>
      </div>
    </div>
    <div class="row">
      <div class="col-sm-12">
        <h2>Total numbers</h2>
      </div>
    </div>
    <div class="row">
      <div class="col-sm-2">
        <p>Numbers for the week</p>
      </div>
      <div class="col-sm-2 text-right">
        21,922
      </div>
      <div class="col-sm-2 text-right">
        $0.00
      </div>
      <div class="col-sm-2 text-right">
        $304,431.37
      </div>
      <div class="col-sm-2 text-right">
        $0.00
      </div>
      <div class="col-sm-2 text-right">
        $0.00
      </div>
    </div>
  </div>
</div>


<style>
  .CompanyName {
    text-align: center;
  }
  
  h2 {
    color: orangered;
    margin-left: 15px;
  }
  
  p {
    font-weight: bold;
    font-size: 15px;
    margin-left: 15px;
  }
  
  p1 {
    text-align: right;
  }
</style>

Take a look at the JsFiddle here.

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

What is the best way to enable CSS IntelliSense for a Nuxt project?

Currently, I am undertaking a project using Nuxt.js and have set up a Docker image to manage all aspects of it. Additionally, I am looking to integrate MDBVue as a CSS library into my project. After some research, I learned that in order to utilize this li ...

Navigating to the following webpage with Selenium using Python

url_main = "https://comic.naver.com/webtoon/detail.nhn?titleId=131385&no=292" This particular website features a comment pagination at the bottom of the page. Upon inspecting the page, I noticed that the buttons were structured like this: &l ...

Is it possible for the background color to change in a sequence every time the page

I'm having trouble figuring out how to create a sequence that changes the background color every time the page is refreshed. I'm comfortable with basic HTML but not so much with JavaScript or CSS. I'm working on a page where I want the backg ...

JS will reach its stopping point at the specified style.zIndex

I am currently in the process of setting up button elements. I have two scripts that correspond to different types of buttons - one script runs a simple collapse menu, while the other executes a more complex collapse by shifting depths and sliding one div ...

Mouse position-based scrolling that preserves click events in the forefront while scrolling

Within a larger div, I have a very wide inner div that scrolls left and right based on the position of the mouse. I found the code for this from an answer at There are two transparent divs above everything else, which capture the mouse position to determ ...

Apply pointer style to the CSS only when a division contains text

If there is plain text inside a div with class="x95qze", how can we add cursor:pointer only to the second div that contains the text Cursor pointer required here. The div with class="x95qze" will not change. The content of the div may ...

Increase the size of the box-shadow so that it extends beyond the boundaries

Can we create a wider box-shadow in CSS than the actual HTML element it is being applied to, while maintaining the same height as the element? Increasing the spread of the shadow typically increases the height as well. In the provided code snippet, the max ...

Ensuring the Angular Material bottom sheet (popover) stays attached to the button

Recently, I've been working on an Angular project where I successfully integrated a bottom sheet from Angular Material. However, I encountered an issue when trying to make the opened popup sticky to the bottom and responsive to its position, but unfor ...

Adjust the image size using CSS within the containing outer div

I am trying to adjust the width of an image using css within typo3. Unfortunately, I only have access to the outer div container which is the custom border of the content element. To make the change, I added the following line to my css file: .Bild-Starts ...

The getTotalLength() method in SVG may not provide an accurate size measurement when dealing with non-scaling-stroke. To obtain the correct scale of

In my current project, I am utilizing JavaScript to determine the length of a path and apply half of that length to the stroke-DashArray. However, I have encountered an issue as I am using vector-effect="non-scaling-stroke" in order to maintain a consisten ...

Is there a way to alter the color of radio buttons?

Is there a way to use CSS to change the background color of a radio button? I've searched online, but all the solutions I found involve JavaScript, which I don't fully understand. I attempted this CSS code, but it didn't have the desired eff ...

Only conceal the breadcrumb trail on the 404 error page

I have recently created a custom node for my site's 404 page with the path /node/83 in the site information. However, I am facing an issue where I cannot hide the .breadcrumb element using display:none. I attempted to achieve this through CSS injector ...

Ways to conceal a div element when the JSON data does not contain a value

If the value in "desc" is empty, then hide <div24> and <popup-desc>. html <div class="popup"> <div class="popup-top" style="background-color: '+e.features[0].properties.fill+';"> ...

Modifying alignment of buttons in React components

Transforming the typical Tic Tac Toe game from the React tutorial, with an added one-player feature. Oddly, button alignment shifts out of place once a value is inserted; causing the button to drop by about 50px until the row is filled with values, after ...

Activate Popover with Hover and simply click anywhere to dismiss

Currently utilizing Bootstrap 4 and intrigued by the popover feature that activates on hover and closes when clicked anywhere. I'm also interested in making links functional within the popover. Any suggestions or tips on how to achieve this? $(doc ...

Using the fieldset element in AngularJS Material causes disruptions in my flex layout

My current issue can be illustrated through two code examples: The first example functions properly when the fieldset is not included. In the second example, including the fieldset causes the layout to extend beyond the window when there is long text (in ...

Styling an HTML Table with CSS to Add Cell Padding

I am trying to add padding to a single cell in my table. I created a class for the td element and specified its style in my CSS file as shown below: .itemQuantity { padding-right:30px; text-align:right; background-color: #EEE; } However, the ...

The concept of the "Centering Effect" refers

Check out the code I have below: http://jsfiddle.net/G8Ste/577/ I want the effect to expand in all directions, not just to the right and bottom. I've experimented with margin: 0, auto, and other CSS and HTML styles to center it, but nothing seems t ...

What is the best way to create a fixed sidebar or top bar that remains visible as I move to different pages?

Whenever I navigate to other pages, the sidebar mysteriously disappears. As I work on my project about an admin page, I'm wondering if it's necessary to include every single page? ...

Dividing one SVG into Multiple SVGs

I'm facing a challenge with loading an SVG overlay on a Google Map. The SVG file is quite large, about 50mb, resulting in a delay of around 10 seconds for it to load in the browser. One solution I'm considering is splitting the SVG into 171 smal ...