Reputation: 8135
For example:
<html>
<head>
<link href="css/style1.css" type="text/css" />
<link href="css/style2.css" type="text/css" />
</head>
<body>
<div>I want to use style1.css within this div<div>
<div>I want to use style2.css within this div<div>
<body>
Is there any posible way to do like that ?
Thank you.
Upvotes: 1
Views: 458
Reputation: 335
If I were you, I also would use classes to define which styles go to which div. However I would not use a separate stylesheet for each class. I would combine the two classes into one stylesheet, because like EvilP said, loading two separate css files can be slow. Also, I would avoid using ids where a class can do the job as effectively, because an id is only used to target one specific element, and a class doesn't have to, but can target more than one element. So a class is more versatile overall.
Upvotes: 0
Reputation: 2672
In your two files define different classes of div
.
For instance, in style1.css you might have:
div.class1
{
background-color: red;
}
And in style2.css you might have:
div.class2
{
background-color: blue;
}
Then change your code to reflect where you want each style, ie:
<div class="class1">I want to use style1.css within this div<div>
<div class="class2">I want to use style2.css within this div<div>
Upvotes: 1
Reputation: 7536
As you wrote, this is not possible but you can give the div-tags id and format for the id only. So you only have to add one css file which gives you a better overview ,structre and the website is loaded faster. The HTML Markup
<div id='first'></div>
<div id='second'></div>
and in the css
#first{
background-color:red;
}
#second{
background-color:green;
}
By using id's you ensure that the access is faster than by using classes. If you want to style the content of the div's differently you could also do that.
Upvotes: 0