.mac{margin-left:auto; margin-right:auto;}
.table{.mac; color:red;}
I want to be able to do that, it doesn't make sense to me why I would need to do:
.table{margin-left:auto; margin-right:auto; color:red;}
I know for the table I could do:
<table class="table mac">
or just type the .table{margin-left:auto; margin-right; color;}
like above but that seems redundant.
Is there some way to do what I'm trying to accomplish in my first statement, is there some special syntax that I'm not aware of to make this work?
Nested rules are defined as a set of CSS properties that allow the properties of one class to be used for another class and contain the class name as its property. In LESS, you can use class or ID selectors to declare mixin in the same way as CSS styles.
Creating a CSS Class Using a Class Selector After adding the code snippet to your styles. css file, save the file. In this code snippet you have added text using the HTML <p> tag. But you have also specified the red-text class by adding the highlighted class attribute class="red-text" inside the opening HTML tag.
With CSS Hero you can easily add classes to elements without needing to touch any of your theme files or adding weird code to your contents. Plus you can control all your classes right from the CSS Hero interface.
You can just add a comma-separated list of classes in . radius , like . radius, . another, .
You can combine multiple CSS selectors on the same line with a comma:
.mac, .table
{
margin-left:auto;
margin-right:auto;
}
.table
{
color:red;
}
The short answer is no, you can't "include" other CSS classes or "inherit" them so to speak.
There are tools you can use to abstract that kind of stuff for you, though. LESS comes to mind. I think the "mixin" is what you're looking for.
Here is a code sample from the LESS front page:
.rounded_corners (@radius: 5px) {
-moz-border-radius: @radius;
-webkit-border-radius: @radius;
border-radius: @radius;
}
#header {
.rounded_corners;
}
#footer {
.rounded_corners(10px);
}
.table, .mac {margin-left:auto; margin-right:auto;}
.table {color:red;}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With