0

I'm using Bootstrap in a project and I want to center a text in some columns of my table.

So I use a class, specified in my tag :

<td class="col_etat" rowspan="4"> MyContent </td>

In my CSS I have :

.col_etat {vertical-align: middle;}

And it doesn't work, we can see that the class in Bootstrap CSS is "over" my class :

(https://i.sstatic.net/LlSoW.png)

It works if I do it without a CSS, but it's not what I want :

<td style="vertical-align: middle;" rowspan="4"> MyContent </td>

If someone knows what I have to do to make it works !

3
  • Can you fiddle your code Commented Aug 12, 2014 at 16:28
  • ".col_etat" could be "html body td.col_etat" to over-power bootstrap without using !important;, which is a bad idea and causes maintenance woes. you should only "go nuclear" and use !important after all else fail, ask any designer... Commented Aug 12, 2014 at 16:30
  • See developer.mozilla.org/en-US/docs/Web/CSS/Specificity for info on how it works. Commented Aug 12, 2014 at 17:41

3 Answers 3

4

Make sure to include styles.css file after bootstrap's CSS file. You might also have to be more specific when defining .col_etat, just like Bootstrap is, so:

.table > tbody > tr > td.col_etat {
  vertical-align:middle;
}

There's a good article about CSS Specificity here

Sign up to request clarification or add additional context in comments.

1 Comment

You're right, it works, I didn't know I had to be more specific, thank's for your help !
0

This looks like it might be an issue with specificity. See: custom css being overridden by bootstrap css for reference.

But in your case, the specificity of your styling class .col_etat is at 10, whereas the bootstrap .table>thead>tr>th is at 13, which is more specific than your styling. You can specify more elements in your custom css in order to make your css override bootstrap's. I would try to avoid using !important if possible.

1 Comment

That's it ! I didn't know the "!important" keyword, but I won't use it, thank's for the advice !
-3

I always just edit the bootstrap css file.

1 Comment

-1 It is considered bad practice to edit core files for any framework/plugin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.