How can I combine multiple CSS rules?

2019-01-12 12:21发布

问题:

div#id_div_allposts {   
    width: 100%;    
}

div.class_div_post {
    width: 100%;
}

div.class_div_editdelete {
    width: 100%;
}

How can i write it in one line ?

And what's the way to select a html tag with id and class ?

回答1:

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%;
}


回答2:

div#id_div_allposts, div.class_div_post, div.class_div_editdelete {
    width: 100%;
}

You can group multiple selectors in CSS via a comma.

Note: The comma starts an entirely new selector from the very start.



回答3:

Use the comma to separate multiple declarations

div#id_div_allposts, div.class_div_post, div.class_div_editdelete {
    width: 100%;
}

Selecting an html tag with and id and class would be

div#ID.class


回答4:

Try this:

div#id_div_allposts, div.class_div_post, div.class_div_editdelete {
    width: 100%;
}

or assuming that you want all div to have width 100% then...

div{
    width: 100%;
}