I want to apply a style to all <p>
and <input>
elements of the numeric
class using css.
Is it possible to consolidate this so that I only write "numeric" once?
p.numeric,input.numeric {
float: right;
}
I'm also using sass, so if it's not possible in CSS is it possible with the sass additions?
When you group CSS selectors, you apply the same styles to several different elements without repeating the styles in your stylesheet. Instead of having two, three, or more CSS rules that do the same thing (set the color of something to red, for example), you use a single CSS rule that accomplishes the same thing.
The HTML class attribute is used to specify a class for an HTML element. Multiple HTML elements can share the same class.
The CSS grouping selector is used to select multiple elements and style them together. This reduces the code and extra effort to declare common styles for each element. To group selectors, each selector is separated by a space.
To specify multiple classes, separate the class names with a space, e.g. <span class="left important">. This allows you to combine several CSS classes for one HTML element.
yes it is possible:
p, input {
&.numeric {
float: right;
}
}
The '&' is necceassry to connect with p/input. Without the result will be p .numeric {...}
You could simply do .numeric, but then it would apply to everything with a class of numeric. If you only want it to apply to paragraphs and inputs then what you're doing is the correct approach.
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