html - 如何将 CSS 应用于 :last-child button

标签 html css css-selectors

参见下面的图片示例,我想知道如何使一行 div 中的最后一个按钮具有不同的颜色。可以在 DIV 中使用 :last-child 使用 CSS 来实现吗?

我想让最后一个按钮像下面的设计一样变成绿色:

谢谢!

Picture example of how i'd like the button to look

HTML:

<div class="span3">
    <h3 class="icon_office">Daily office cleaning</h3>
    <p>Office, meeting rooms, communal areas, washrooms and hygiene areas.</p>
    <a class="btn btn-large btn-primary" href="#>Learn More</a>
</div>

<div class="span3">
     <h3 class="icon_retail">Retail cleaning</h3>
     <p>The cleaning and maintenance of public circulation areas, shopping centres, retail complexes etc.</p>
     <a class="btn btn-large btn-primary" href="#">Learn More</a>
</div>

<div class="span3">
     <h3 class="icon_edu">Educational cleaning</h3>
     <p>The general cleaning of all aspects of public sector establishments, schools and colleges.</p>
     <a class="btn btn-large btn-primary" href="#">Learn More</a>
</div>

<div class="span3">
    <h3 class="icon_special">Specialist cleaning</h3>
    <p>We also provide specialist cleaning and support services.</p>
    <a class="btn btn-large btn-primary" href="#">Learn More</a>
</div>

最佳答案

使用 :last-child:

.services .span3:last-child .btn {
   background : green;
}

使用相邻兄弟选择器:

.services .icon_special + p + .btn {
    background: green;
}

关于html - 如何将 CSS 应用于 :last-child button,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24151714/

相关文章:

html - @font-face src :local() does not work on some fonts

javascript - 单击响应菜单时导航按钮会移动

html - 如何制作 CSS 定义的表格单元格滚动条?

html - 如果窗口溢出,如何使 "position:fixed"的 div 远离屏幕?

reactjs - 当使用 Material UI 样式将鼠标悬停在父级上时,如何更改子级的样式?

CSS/样式标题标签

css - 后代和子代选择器

html - 来自图像 css 的 div Angular

html - 如何制作 2 个柔性 block 和 1 个固定 block ?

javascript - Jquery - 滚动到顶部调整位置