Text alignment class inside table

This article was translated from: Text-align class for inside a table

Is there a set of classes in Twitter's Bootstrap framework that aligns text? Is there a set of text alignment classes in Twitter's Bootstrap framework ?

Example the For, the Tables with the I have have some $totals that aligned the I want to at The right ... for example, I have some amounts to $the table, I think right alignment ...

<th class="align-right">Total</th>

and and

<td class="align-right">$1,000,000.00</td>

#1st Floor

Reference: https://stackoom.com/question/rpZA/ Text alignment within the table


#2nd Floor

I guess because CSS already has text-align:right, AFAIK, Bootstrap doesn't have a special class for it. I guess because CSS already has text-align:right, AFAIK, Bootstrap has no special classes.

Bootstrap does have "pull-right" for floating divs, etc. to the right. The right side of Bootstrap does have a "pull right" function for floating divs, etc.

Bootstrap 2.3 just came out and added text alignment styles: Bootstrap 2.3 just came out and added text alignment styles :

Bootstrap 2.3 released (2013-02-07) Bootstrap 2.3发布 (2013-02-07)


#3rd floor

No, Bootstrap doesn't have a class for that, but this kind of class is considered a "utility" class, similar to the ".pull-right" class that @anton mentioned. No, Bootstrap does not provide a class for this, But this class is considered a "utility" class, similar to the ".pull-right" class mentioned by @anton.

If you look at utilities.less you will see very few utility classes in Bootstrap, the reason being that this kind of class is generally frowned upon, and is recommended to be used for either: a) prototyping and development-so you can quickly build out your pages, then remove the pull-right and pull-left classes in favor of applying floats to more semantic classes or to the elements themselves, or b) when it's clearly more practical than a more semantic solution. If you look at utilities.less , Then you will see few utility classes in Bootstrap, because this class is generally not accepted, it is recommended for any of the following: a) Prototyping and development-so you can quickly build and move out the page, and then delete The upper-right and upper-left classes to apply floating-point numbers to more semantic classes or elements themselves, or b) when it is clearly more practical than a more semantic solution.

In your case, by your question it looks like you wish to have certain text align on the right in your table, but not all of it. As far as your situation is concerned, according to your question, you seem to want some of the table The text is aligned, but not all. Semantically, it would be better to do something like (I'm just going to make up a few classes here, except for the default bootstrap class, .table): Semantically, it is better to do something similar (I will Here are some classes, except the default boot class .table):

  <table class="table price-table">
    <thead>
      <th class="price-label">Total</th>
    </thead>
    <tbody>
      <tr>
        <td class="price-value">$1,000,000.00</td>
      </tr>
    </tbody>
  </table>

And just apply the text-align: leftor text-align: rightdeclarations to the price-value and price-label classes (or whatever classes work for you). Just apply text-align: leftor text-align: rightdeclare to the price-value and price-label classes (or any class that suits you) .

Applying problem with at The align-rightAS A class, that IS IF you want to your Refactor by Will you have have to redo the Tables at The Markup and at The Styles. The align-rightproblem is that as a class, if you want to reconstruct the table, you must redo tags and style. If you use semantic classes you might be able to get away with refactoring only the CSS content. If you use semantic classes, you may be able to get rid of the predicament by only refactoring the CSS content. Plus, if are taking the time to apply a class to an element, it's best practice to try to assign semantic value to that class so that the markup is easier to navigate for other programmers (or you three months later). In addition, if you spend When you apply a class to an element, the best practice is to try to assign semantic values ​​to the class so that the tag is easy for other programmers (or three months later) to browse.

One way to think of it is this: when you pose the question "What is this td for?", You will not get clarification from the answer "align-right". One way of thinking is: when you ask the question "this What is td used for? ", you will not get clarification from the" align-right "answer.


#4th floor

The .text-alignclass is totally valid and more usable than having a .price-labeland .price-valuewhich are of no use any more. The class is totally valid and more useful .text-alignthan having and useful..price-label.price-label.price-value

I recommend going 100% with a custom utility class called I recommend 100% named

.text-right {
  text-align: right;
}

I like to do some magic, but that is up to you, like something: I like to do some magic, but it depends on you, for example:

span.pull-right {
  float: none;
  text-align: right;
}

#5th Floor

Bootstrap 3 Bootstrap 3

Text Alignment Docs v3 v3-aligned text file

<p class="text-left">Left aligned text.</p>
<p class="text-center">Center aligned text.</p>
<p class="text-right">Right aligned text.</p>
<p class="text-justify">Justified text.</p>
<p class="text-nowrap">No wrap text.</p>

Bootstrap 3 text alignment example

Bootstrap 4 Bootstrap 4

Text Alignment Docs V4 V4 text alignment file

<p class="text-xs-left">Left aligned text on all viewport sizes.</p>
<p class="text-xs-center">Center aligned text on all viewport sizes.</p>
<p class="text-xs-right">Right aligned text on all viewport sizes.</p>

<p class="text-sm-left">Left aligned text on viewports sized SM (small) or wider.</p>
<p class="text-md-left">Left aligned text on viewports sized MD (medium) or wider.</p>
<p class="text-lg-left">Left aligned text on viewports sized LG (large) or wider.</p>
<p class="text-xl-left">Left aligned text on viewports sized XL (extra-large) or wider.</p>

Bootstrap 4 text alignment example


#6th floor

2.3 Utility classes has on Bootstrap text-left, text-right, and text-center, But Not Work in Table They do cells. On Bootstrap 2.3 having utility classes text-left, text-rightand text-center, but they do not work in the table cell. Until Bootstrap 3.0 is released (where they have fixed the issue) and I am able to make the switch, I have added this to my site CSS that is loaded after bootstrap.css: Before the release of Bootstrap 3.0 (they have solved the problem), and Being able to switch, I added it to the bootstrap.csssite CSS that I loaded later:

.text-right
{
    text-align: right !important;
}

.text-center
{
    text-align: center !important;
}

.text-left
{
    text-align: left !important;
}
Published 0 original articles · praised 8 · 30,000+ views

Guess you like

Origin blog.csdn.net/asdfgh0077/article/details/105472649