Warm tip: This article is reproduced from serverfault.com, please click

html-内部元素的CSS选择器

(html - CSS selector of inner elements)

发布于 2020-11-28 00:01:54

我想选择单词“ dashboard ”,“出勤”,“ Marcum”和“结果”,并将它们的颜色设置为“白色”。

    <div class="container-fluid">
    <div class="row">
    <div class="col-md-12">


                <div class="fpstartwrap">
                <div class="fpstart">
                    <div class="iconset">

                            <div class="btn btn-secondary">
                                <a role="button" href="https://rafiee.net" title="Dashboard" 
                                   alt="Dashboard" target="_blank">
                                    <div class="navicon" align="center">
                                        <i class="fa fa-3x fa-home"></i>
                                    </div>
                                    Dashboard
                                </a>
                            </div>
                            <div class="btn btn-secondary">
                                <a role="button" href="https://rafiee.net/attendance" 
                                   title="Attendance" alt="Attendance" target="_blank">
                                    <div class="navicon" align="center">
                                        <i class="fa fa-3x fa-user-times"></i>
                                    </div>
                                    Attendance
                                </a>
                            </div>
                            <div class="btn btn-secondary">
                                <a role="button" href="https://rafiee.net/q" title="Marcum" 
                                      alt="Marcum" target="_parent">
                                    <div class="navicon" align="center">
                                        <i class="fa fa-3x fa-calculator"></i>
                                    </div>
                                    Marcum
                                </a>
                            </div>
                            <div class="btn btn-secondary">
                                <a role="button" href="https://rafiee.net/user/" title="Results" 
                                       alt="Results" target="_self">
                                    <div class="navicon" align="center">
                                        <i class="fa fa-3x fa-id-card-o"></i>
                                    </div>
                                    Results
                                </a>
                            </div>


                        
                    </div>
                </div>
                </div>

                    <div class="collapse" id="fpslider">
                        <div class="row">
    <div class="col-md-3">
        <a class="btn btn-primary" href="https://rafiee.net">Rafiee.net</a>
    </div>
    <div class="col-md-3">
        <a class="btn btn-primary" href="https://rafiee.net/attendance">Attendance</a>
    </div>
     <div class="col-md-3">
        <a class="btn btn-primary" href="https://rafiee.net/dailybonus">Daily Bonus</a>
    </div>
     <div class="col-md-3">
        <a class="btn btn-primary" href="https://rafiee.net/q">Marcum Calculator</a>
    </div>
</div>
                    </div>
                <div style="clear:both;"></div>



</div>
</div>
</div>

我想通过以下方式做到这一点:

div a[role="button"] {
color: white;
}

但是,由于我还有其他具有“按钮”角色的元素,因此它们都被更改为白色,这对我而言是不希望的。我只需要针对这四个词。是否可以?任何帮助都需要提前感谢。谢谢

Questioner
Majid
Viewed
22
Johannes 2020-11-29 00:12:07

使用选择器中的父元素来更具体:

.fpstartwrap > .fpstart > .iconset > div.btn.btn-secondary a[role="button"] {
  color: white;
}

或仅将类别应用于仅用于这四个按钮的那些按钮,然后在选择器中使用该类别。