Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using two css files in the same html file

Is it possible to use 2 CSS classes that have the same name for the selectors, etc. in the same HTML file? If so, how do you differentiate between the two when styling elements?

like image 526
Xaisoft Avatar asked Dec 16 '08 20:12

Xaisoft


People also ask

Can I use 2 CSS files in HTML?

Yes, It is possible to include one CSS file in another and it can be done multiple times. Also, import multiple CSS files in the main HTML file or in the main CSS file. It can be done by using @import keyword.

What will happen if an HTML page links 2 or more CSS files that will make changes to the same HTML element?

All CSS rules in a document are internally fused into one. In the case of rules in both style sheets that apply to the same element with the same specificity, the style sheet embedded later will override the earlier one.

How do I link CSS to same file in HTML?

CSS can be added to HTML documents in 3 ways: Inline - by using the style attribute inside HTML elements. Internal - by using a <style> element in the <head> section. External - by using a <link> element to link to an external CSS file.


2 Answers

Yes this is possible, simply include two css files in the HEAD section of the document. Any styles set in the first will be overwritten in the second, so say you have this:
First file:

 #something{
  background-color: #F00;
  color: #FFF;
 }

And then in the second file:

 #something{
  background-color: #000;
 }

Then the background color for #something will be overwritten in the second file to black but the color will stay the same since the second file doesn't say anything about it.

like image 162
Pim Jager Avatar answered Sep 25 '22 04:09

Pim Jager


Yes it is possible. The definitions in second file will overwrite the definitions of the first file. There is no way to differentiate between the two but to prepend the class names according to the file.

like image 45
fasih.rana Avatar answered Sep 25 '22 04:09

fasih.rana