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

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

举一个例子:

  1. .footer #one .flag li .drop_down form div{
  2. width: 80px;
  3. font-family: Arial,Helvetica,sans-serif;
  4. font-size: 11px;
  5. text-align: left;
  6. line-height: 1.5;
  7. color: #ccc;
  8. font-weight:bolder;
  9. margin-left: 30px;
  10. }
  11. .footer #two .flag li .drop_down form div{
  12. width: 80px;
  13. font-family: Arial,sans-serif;
  14. font-size: 11px;
  15. text-align: left;
  16. line-height: 1.5;
  17. color: #ccc;
  18. font-weight:bolder;
  19. margin-left: 30px;
  20. }

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

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

解决方法

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

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.

猜你在找的HTML相关文章