3
Situation
I have several files css
, some of mine, some of libraries.
Doubt
- What is the best way to block the
css
external to certain elements?
Example
Current Effect
/***** CSS EXTERNO *****/
form div{
padding: 5px;
clear:both;
}
/***** OUTRO CSS EXTERNO *****/
div div{
margin: 10px;
}
div label{
font-size: 20px;
}
/***** MEU CSS *****/
.content-form>div{
border:1px solid #CCC;
float:left;
min-width:50px;
min-height:10px;
text-align:center;
}
.content-form>div>label{
color:blue;
}
<div>
<form class="content-form">
<div>
<label>Item 1</label>
</div>
<div>
<label>Item 2</label>
</div>
<div>
<label>Item 2</label>
</div>
<div>
<label>Item 3</label>
</div>
</form>
</div>
Note that here the external css are interfering with the result I want, for the css I’ve assembled.
Desired Effect
.content-form>div{
border:1px solid #CCC;
float:left;
min-width:50px;
min-height:10px;
text-align:center;
}
.content-form>div>label{
color:blue;
}
<div>
<form class="content-form">
<div>
<label>Item 1</label>
</div>
<div>
<label>Item 2</label>
</div>
<div>
<label>Item 2</label>
</div>
<div>
<label>Item 3</label>
</div>
</form>
</div>
Note
- I cannot remove the files as some css are used elsewhere
- I can’t remove the
css
specific, because they are used in other elements, I just want to inactivate it for that specific element.
Current attempt
/***** CSS EXTERNO *****/
form div{
padding: 5px;
clear:both;
}
/***** OUTRO CSS EXTERNO *****/
div div{
margin: 10px;
}
div label{
font-size: 20px;
}
/***** MEU CSS *****/
form.content-form div{
padding:0;
clear:none;
}
div .content-form div{
margin:0;
}
div .content-form div label{
font-size:inherit;
}
.content-form>div{
border:1px solid #CCC;
float:left;
min-width:50px;
min-height:10px;
text-align:center;
}
.content-form>div>label{
color:blue;
}
<div>
<form class="content-form">
<div>
<label>Item 1</label>
</div>
<div>
<label>Item 2</label>
</div>
<div>
<label>Item 2</label>
</div>
<div>
<label>Item 3</label>
</div>
</form>
</div>
Note that here I am basically overwriting all external css.
It tries to change their inclusion position. It also affects.
– Wallace Maxters
@Wallacemaxters yes, but only if it’s the same sentence
file1 - div div{}
,file2 - div div
, ai the second overwrite the first, the problem is that it is the specificity that each file is giving.file1 - div div{}
,file2 - form div{}
then he interprets as different things and generates a "merge", which is not desired.– Guilherme Lautert
Why can’t you remove some files? Can’t you also generate a single file by joining and removing styles? Can’t you even modify the names? Because the specificity of each element is very broad, I believe that this is the biggest negative point.
– celsomtrindade
@Celsomtrindade I certain moments other elements are rendered and use the same css and apply correctly, however for the element I’m wanting to render it also applies and is not what I draw, so I am generating a superscript code, yet I wonder if there’s any better way.
– Guilherme Lautert
At least I don’t know any technique that is not to overwrite when we use another file
css
, other than the call order of the archives, as already mentioned by @Wallacemaxters . In this case, I believe that you should really create rules that override the desired properties.– celsomtrindade
Although not designed for this, you can use the operator
!important
to give more emphasis on the desired rule– Adriano Luz