Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My CSS are overridden by Bootstrap CSS

I want to add GWT-Bootstrap to my already-started project. I managed to use it, but the Bootstrap CSS is overriding every other CSS. The result is that all my previous UI elements are mixed up.

The margin, the text size, and a lot of elements don't fit any more. I can't use Bootstrap because all the rest of the project is unusable. I would like to do a progressive change to Bootstrap and keep the old stuff like it is.

I would like to have my CSSs in this priority order:

  • MyApp
  • GWT
  • Bootstrap

I tried to order them in my *.gwt.xml without success:

<stylesheet src="css/gwt-bootstrap.css" />
<stylesheet src="css/bootstrap.min.css" />
<stylesheet src="gwt/clean/clean.css" />
<stylesheet src="MyApp.css" />

What can I do?

like image 517
FrozZerrer Avatar asked Jul 10 '13 21:07

FrozZerrer


1 Answers

The priority of using styles is driven by more complicated algorithms than just an order on inclusion in HTML. The CSS style is chosen with the most specific selection rule, where inline rules are considered more specific then externally attached, then selection by ID, then the class and at the end selection with tag name. For example, the paragraph <p id="xyz" class="xyz"> will be red independently of the order of rules:

.xyz {
  color: blue;
}
#xyz {
  color: red;
}

If there are two rules with the same selection type, the number matters. So, selection .xyz .abc is "stronger" then .qwerty.

If two rules have equivalent selection in terms of numbers in each category, then, in the very end order is taken into account...

You can also force a different order with the !important directive.

Read more about it with "CSS specificity" keywords.

like image 89
Marcin Skórzewski Avatar answered Oct 27 '22 08:10

Marcin Skórzewski