-1

I'm learning HTML/CSS, and I've seen some examples like using .text-center for text-align: center; (in Bootstrap3).

That is a little bit strange for me, because these classes' css style will never change, so I have to change their class when I need to change their style. For example, if I have to change an element with class="text-center" to text-align: right;, I'll change the class it uses to class="text-right" instead of changing class text-center's style.

Is there a detailed reason to use these fixed classes?

If so what is the general rule for using/not using fixed classes?

ik1ne
  • 1,041
  • 15
  • 20
  • I think this is **pos** off-topic.. reason being, it's all preference. I'd personally prefer setting generic classes (e.g. text-center, text-right etc.) but someone else might prefer something else ... – treyBake Dec 10 '18 at 12:32
  • This is the problem with abusing classes the way bootstrap and all similar frameworks do. If you want to use them, you have to give up on using semantic content class names in the way HTML and CSS binding was designed to work. – Alohci Dec 10 '18 at 12:35
  • 1
    personally I don't like having classes for each style - it will end up bloating both your css and html files. Probably why I don't use boostrap - too much bloat – Pete Dec 10 '18 at 13:09
  • 1
    First of all, there is no `mt-10` class, and the numbers (0-5) respresent spacer units not px. Read the docs and https://stackoverflow.com/questions/35363194/how-do-i-use-the-spacing-utility-classes-on-bootstrap-4 – Carol Skelly Dec 10 '18 at 13:34
  • @Zim Thank you for pointing that out, I must have confused that with something like [this one](https://gist.github.com/ykessler/6eb7d6656ea446c5deeb). I'm going to remove `mt-x` part of the question. – ik1ne Dec 10 '18 at 14:37
  • 1
    @Pete - Very true. But more than that, once you have classes for each style, specificity no longer makes any sense. Which is why almost everybody finds themselves battling against it. – Alohci Dec 10 '18 at 16:16

1 Answers1

1

It depends how you manage your css.

Many avoid inserting style tags or css classes in their html tags, to avoid spending too long modifiying it afterwards.

However, sometimes, you can't make your css specific enough to apply a "text-center" to a tag without changing it somewhere else. So adding it directly to your html tag will allow specific modification.

Using classes instead of style tags makes your code look cleaner and you have one less parameter to check when going through it.

I hope I answered your question!

CHtt
  • 11
  • 1