html – 如何为两个标签设置一个CSS规则?

前端之家收集整理的这篇文章主要介绍了html – 如何为两个标签设置一个CSS规则?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想知道如何为两个不同的类设置一个设置。

举一个例子:

.footer #one .flag li .drop_down form div{
    width: 80px;
    font-family: Arial,Helvetica,sans-serif;
    font-size: 11px;
    text-align: left;
    line-height: 1.5;
    color: #ccc;
    font-weight:bolder;
    margin-left: 30px;
}
.footer #two .flag li .drop_down form div{
    width: 80px;
    font-family: Arial,sans-serif;
    font-size: 11px;
    text-align: left;
    line-height: 1.5;
    color: #ccc;
    font-weight:bolder;
    margin-left: 30px;
}

这两个规则都有相同的内容。区别只是第二个标签。有办法做这样的事吗?

.footer >>>#one and #two<<<< .flag li .drop_down form div{
        width: 80px;
        font-family: Arial,sans-serif;
        font-size: 11px;
        text-align: left;
        line-height: 1.5;
        color: #ccc;
        font-weight:bolder;
        margin-left: 30px;
    }

解决方法

用逗号分隔选择器:
.footer #one .flag li .drop_down form div,.footer #two .flag li .drop_down form div {
    /* Rules */
}

selectors level 3 spec

A comma-separated list of selectors represents the union of all elements selected by each of the individual selectors in the list. (A comma is U+002C.) For example,in CSS when several selectors share the same declarations,they may be grouped into a comma-separated list. White space may appear before and/or after the comma.

原文链接:https://www.f2er.com/html/233312.html

猜你在找的HTML相关文章