How can I combine multiple CSS rules?
All you have to do is separate them with a comma e.g
div#id_div_allposts,
div.class_div_post,
div.class_div_editdelete {
width:100%;
}
How to combine multiple selectors for the same rule
To group CSS selectors in a style sheet, you use commas to separate multiple grouped selectors in the style. In this example, the style affects two classes input#input_9_2
and input#input_9_3
.
input#input_9_2,
input#input_9_3
{
max-width: 500px;
}
The comma means "and", so this selector applies to all input#input_9_2
elements and input#input_9_3
elements. If the comma were missing, the selector would instead apply to all input#input_9_3
elements that are a child of an input#input_9_2
. That is a different kind of selector, so the comma is important.
Any form of the selector can be grouped with any other selector.
Is it possible make a CSS rule that combines two or more other CSS rules?
The only way to combine CSS classes into one like that, that I know of, is to use a CSS pre-processor like LESS or SASS.
If you don't want to use that, I'm afraid you have to assign both classes separately.
combine multiple css styles into one
In bootstrap 4, the css for .alert is
.alert {
position: relative;
padding: 0.75rem 1.25rem;
margin-bottom: 1rem;
border: 1px solid transparent;
border-radius: 0.25rem;
}
and for .alert-secondary
.alert-secondary {
color: #464a4e;
background-color: #e7e8ea;
border-color: #dddfe2;
}
So to combine them, use:
.login-alert-combined{
font-family: 'Kavivanar', cursive;
position: relative;
padding: 0.75rem 1.25rem;
margin-bottom: 1rem;
border: 1px solid transparent;
border-radius: 0.25rem;
color: #464a4e;
background-color: #e7e8ea;
border-color: #dddfe2;
}
But I don't see what is wrong with setting class as "alert alert-secondary login-alert" when you want to use all 3 styles.
Related Topics
How to Import Local Image Using Knitr for Markdown
HTML5 Input for Money/Currency
Automatic Retina Images for Web Sites
Why Do Symbols Like Apostrophes and Hyphens Get Replaced with Black Diamonds on My Website
CSS Selector for Text Input Fields
Flex Child Is Growing Out of Parent
CSS Flex Box Last Space Removed
Making Part of a Div Transparent
Using Cm/Mm on The CSS of a Web App That Replicates Paper Interaction Is a Good Practice
How to Make Rounded Border in Ie8 with CSS
How to Style and Align Forms Without Tables
W3C Markup Validator Ampersand (&) Error
How to Display HTML Code (Entities) on a Web Page
How to Conditionally Display Element Attributes Using Angular2