Frequently asked questions regarding theming in OpenUI5
While there is always the option to create a new Theme, this is overkill for most minor style adaptations. For those minor changes, the recommendation is to include additional CSS into the page which changes the style of the respective tags of the OpenUI5 control. This allows complete, arbitrary changes of the visual design - after all it is the same technology that the UI5 controls use for their styling.
The main options are:
One tricky thing is that a control usually does not map to ONE HTML element, but to a whole tree of HTML elements. Whatever is set to the 'style' property we would probably add to the root element of this HTML tree – and only there, so you have no 'style' access to inner parts. If you just want to override the height of a button, this would actually work. But as soon as things get more complex, it will not work that easy. And “more complex” already starts with the height of a ComboBox. The outer <div> will get the proper height, yes. And incidentally also the <input> tag inside, as it has 100% height set. But the dropdown arrow and the respective button-kind-of-thing has a fixed height and the whole control will look pretty broken, then.
In other cases, when HTML elements are nested that break the CSS inheritance chain e.g. like a <table> does for font settings, you may change the "style" to a different font and text color, but it will just do nothing.
In general, we try to expose the obvious adaptation stuff in the API, for example the button height. But the less obvious adaptations may require support inside the control to work properly and as we cannot foresee and support everything you can do with a 'style' property, we raise the bar a little bit by requiring you to write CSS (potentially using .addStyleClass(…) on the respective control). With CSS you can do what you cannot do with a 'style' property: tweak the inner HTML components of a control.
Plus: SAP applications (at least the more traditional ones – currently this seems to be less of a rule, but I’m not sure it will stay like this forever) need to conform to some visual design guideline and in general it is not even desired that applications change the TextField height or used font however they like. As you can use CSS, UI5 still supports that, but we shouldn’t make breaking the visual design an option in our official API.
When OpenUI5 is used "normally" (which means: loaded by a <script> element in the <head> of a page, all libraries declared in the respective attribute of the script tag), it is sufficient to just add the custom CSS at any place after the OpenUI5 <script> element. OpenUI5 will insert its CSS links immediately after the <script> tag, so any later CSS will appear later in the document and can thus overwrite the OpenUI5 CSS.
However, it is important to understand the precedence rules of CSS!
The order of appearance is not the only factor deciding which one of two or more conflicting rules wins. Actually it is only the least important factor. In practice, the most important (and maybe least known) factor is the "specificity" of the selector belonging to a rule.
For example, if one rule says button {color:red;} to make all button texts red and a second rule says div > button {color:green;} to make all texts green in buttons which are direct children of a <div> element, the second rule always wins, if applicable, because it is more specific. The order of appearance in the document does not matter in this case. It would only matter if both rules would start with an equal selector like button{color:***}.
The order of loading is completely irrelevant, only the position in the document counts in this case.
If you load OpenUI5 not with a <script> tag in the <head>, or if you did not specify all used control libraries in the <script> tag, but loaded some later on when the body was already loaded, you can still make sure a custom CSS appears later in the document by loading it with jQuery.sap.includeStyleSheet(stylesheetUrl[, id]) after loading OpenUI5 or the dynamically loaded control library.
If you want to change some styling and use control.addStyleClass(…) to add a CSS class, but it does not seem to work, you first have to understand WHAT is not working:
You can check this by inspecting the HTML with your browser's developer tools/ web inspector.
Depending on the answers it may be that one should not even create a new theme but just adapt an existing one.