如何在两个条件类中选择多个类?

时间:2016-01-13 17:09:05

标签: css css-selectors

HTML代码:

<html class="mobile portrait">
    <body>
        <div>
            <header>
                <img class="company_logo">
            </header>
            <section>
                <div>
                    <img class="company_logo">
                </div>
            </section>
            <footer>
                <img class="company_logo">
            </footer>
        </div>
    </body>
</html>

为了display: none;,我如何在.company_logo期间将一条规则应用于.mobile .portrait?:

更新 编辑HTML代码以添加多个company_logo。代码已从问题中删除:

/* CSS code */
.mobile .portrait > body > div > header > .company_logo {
    display: none;
}

1 个答案:

答案 0 :(得分:4)

/* Matches elements with the class of company_logo that are
   inside an element with both "mobile" and "portrait" classes */
.mobile.portrait .company_logo {
    /* style here */
}