@Chun is right when he said that his HTML "hierarchy" should not be implemented like this.
However solving the "problem", you can include "priorities" in your selectors, example:
.tema-1 .btn, .tema-2 .tema-1 .btn{
background-color:#975167;
border-color:#774137;
}
.tema-2 .btn, .tema-1 .tema-2 .btn{
background-color:#36c1ab;
border-color:#26819b;
}
The selector .tema-2 .tema-1 .btn
has predominance over the .tema-2 .btn
, even being before. As well as the .tema-1 .tema-2 .btn
about the .tema-2 .btn
. If you have 10 themes you will have to do this for everyone in each rule:
.tema-1 .btn,
.tema-2 .tema-1 .btn,
.tema-3 .tema-1 .btn,
.tema-4 .tema-1 .btn,
.tema-5 .tema-1 .btn,
.tema-6 .tema-1 .btn,
.tema-7 .tema-1 .btn,
.tema-8 .tema-1 .btn,
.tema-9 .tema-1 .btn,
.tema-10 .tema-1 .btn,{
background-color:#975167;
border-color:#774137;
}
.tema-1 .controle,
.tema-2 .tema-1 .controle,
.tema-3 .tema-1 .controle,
.tema-4 .tema-1 .controle,
.tema-5 .tema-1 .controle,
.tema-6 .tema-1 .controle,
.tema-7 .tema-1 .controle,
.tema-8 .tema-1 .controle,
.tema-9 .tema-1 .controle,
.tema-10 .tema-1 .controle,{
/* Regras */
}
.tema-1 .alerta,
.tema-2 .tema-1 .alerta,
.tema-3 .tema-1 .alerta,
.tema-4 .tema-1 .alerta,
.tema-5 .tema-1 .alerta,
.tema-6 .tema-1 .alerta,
.tema-7 .tema-1 .alerta,
.tema-8 .tema-1 .alerta,
.tema-9 .tema-1 .alerta,
.tema-10 .tema-1 .alerta,{
background-color:#975167;
border-color:#774137;
}
This would look bad to manage, so you could use a Pre-processor, like LESS or SASS. And do something like:
.tema-1,
.tema-2 .tema-1,
.tema-3 .tema-1,
.tema-4 .tema-1,
.tema-5 .tema-1,
.tema-6 .tema-1,
.tema-7 .tema-1,
.tema-8 .tema-1,
.tema-9 .tema-1,
.tema-10 .tema-1{
.btn {
/* Regras */
}
.controle {
/* Regras */
}
.alerta {
/* Regras */
}
}
Functional example:
.box{
background-color:rgba(0,0,0,0.08);
padding:5px;
}
.box .box{margin: 10px 0 0 10px;}
.btn{
border: 1px solid #CF8A5B;
border-radius:2px;
background-color: #DFAA5B;
color:#333;
padding:3px;
margin:5px 0;
cursor:pointer;
}
.tema-1 .btn, .tema-2 .tema-1 .btn{
background-color:#975167;
border-color:#774137;
}
.tema-2 .btn, .tema-1 .tema-2 .btn{
background-color:#36c1ab;
border-color:#26819b;
}
<div class="box">
Padrão: <button class="btn">Botão</button>
<div class="box tema-2">
Tema 2:
<button class="btn">Botão</button>
<div class="box tema-1">
Tema 1:
<button class="btn">Botão</button>
<div class="box tema-2">
Tema 2:
<button class="btn">Botão</button>
</div>
</div>
</div>
</div>
The
tema-1
is supposed to be inside thetema-2
in HTML? It doesn’t seem right by its hierarchy...– Chun
This shouldn’t be within a function
if/else
inPHP
orJavascript
? Because from what I understand what you want to do here is: whether the option oftema-1
is selected - run HTML code<div class='tema-1'></div>
or if the optiontema-2
is selected -<div class='tema-2'></div>
– Chun
The intention is that each theme overwrites the previous one respecting the order in html. Numbered names are just examples.
– Oeslei
Take a look at in my reply @Oeslei . If she helped you solve your problem, please consider marking it as correct. =)
– Chun
@Chun I asked the question just a simple example. The change is not just for the
background
. I would like to be able to apply the styles to the elements according to the nearest theme defined. Take as an example theRelativeLayout
and theLinearLayout
android with a structure of typeLinearLayout > RelativeLayout > LinearLayout
.– Oeslei
This example I posted in the answer is just for you to get a sense of how to apply the styles later in your
CSS
. Did you also check my jsFiddle example? There’s also an example in jsFiddle with more styles as an example of how this would work on a real website.– Chun