I have a html file which loads with two css files as follows,
<html>
<head>
<link rel="stylesheet" type="text/css" href="style1.css">
<link rel="stylesheet" type="text/css" href="style2.css">
</head>
<body class="theme-css">
<div id="mywidget">
<label>Textbox</label>
<input type="text" value="name" />
</div>
</body>
</html>
And the styles inside two style files is,
style1.css
.theme-css input[type="text"] {
color: red;
}
style2.css
#mywidget input[type="text"] {
width : 100%;
}
Both style1 and style2 apply styles to input text box but on different css attributes. So, when i load the page, the input text box in my widget gets red color from the theme-css style in style1.css and it gets 100% width from the mywidget style in style2.css.
My requirement is that , can we restrict the styles being applied inside the mywidget div with only styles from one css file. (i.e) From the above example , i do not want red color on text box being applied from style1.css, i only want the 100% width from style2.css. Can the styles be restricted inside a div to be loaded only from a particular stylesheet ?
I know this can be achieved by overriding the color attribute for input type text box in style2.css as follows,
#mywidget input[type="text"] {
color: initial;
width : 100%;
}
The above overriding might not help as the widget can be loaded in different websites. And different websites have different themes with different styles. So, the overridden css of one site may not hold good for another website. This does not help in CSS scaling and maintaining a single css file for multiple websites with different themes.
Could this be done in any other way, such that i need not override the css for every element , which has styles in parent css ?
We went for a JavaScript widget approach to avoid using iframe.
I have found cleanslate.css, which was mentioned will solve css issues for js widgets. But the problem is I need to add ! important for all my styles. Is this the correct approach. Any suggestions ??