I am working on a website that was built four or five years ago and I ran across something that I have never seen before. Who ever built the site is using both classes (.home.product) to call any sub-elements (.banner) in the page. I didn’t think you could do this, but obviously it works. Is this a hack or is it kosher? If this is ok to do can you also do it with an ID? (Example: #home.product)? I hope my question makes sense.
<head>
<style>
.home.product .banner{
background:#d1d1d1;
border:solid 1px #000;
width:500px;
height:150px;
}
</style>
</head>
<body class="home product">
<div class="banner">Blah Blah Blah</div>
</body>
Thanks for the help!
It is perfectly valid and normal to specify multiple classes on a single HTML element, and to target them with multiple, chained class selectors in CSS. There’s nothing hacky about it at all.
And yes, you can also chain any number of ID selectors, class selectors, attribute selectors and pseudo-classes with one another in any order. Both
#home.productand.product#homeare equivalent, matching an element with an ID ofhomeas well as aproductclass.