html...
<div id="main">
<div class="news"></div>
</div>
How could I assign css for #main
id which has .news
class with pure css ?
Is there something like #main:only(.news){...}
?
html...
<div id="main">
<div class="news"></div>
</div>
How could I assign css for #main
id which has .news
class with pure css ?
Is there something like #main:only(.news){...}
?
You could keep using the #main id and then apply a class to the same element with it's own styles that could override the default #main styles, something like
<div id="main" class="news">
</div>
Then you could write a css rule like this
#main.news {
/* your css rules go here */
}
I often use a body class to allow me to distinguish a common id from one page to another
<body class="news-page">
<div id="main">
<div class="news">
then your css can do thus
.news-page #main {
background: blue;
{
.another-page #main {
background: green;
}
.news {
background: red;
}
How about something like this? You can target id="main" with #main and class="news" with .news.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style type="text/css"
#main { color: red; }
.news { color: blue; }
</style>
</head>
<body>
<div id="main">
This is #main
<div class="news">
This is .news
</div>
</div>
</body>
</html>