【问题标题】:how identify first anchor tag in sass in a class?如何在类中识别 sass 中的第一个锚标记?
【发布时间】:2016-09-24 16:28:24
【问题描述】:

假设如下sn -p

<div class="class-a">
   <a href="#">Hello</a>
   <ul>
     <li>
       <a href="#">Hello A</a>
     </li>
     <li>
       <a href="#">Hello B</a>
     </li>
   </ul>
</div>

如何通过 sass 在 class-a 中选择包含 hello 文本的标签。请帮我。

【问题讨论】:

标签: html css sass


【解决方案1】:

试试这个:

HTML

<ul>
    <li>a</li>
    <li>b</li>
    <li>c</li>
    <li>d</li>
</ul>

SCSS

$colors: red, orange, yellow, green, blue, purple;

@for $i from 1 through length($colors) {
  li:nth-child(#{length($colors)}n+#{$i}) {
    background: lighten(nth($colors, $i), 20%);
  }
}

查看直播:https://codepen.io/cimmanon/full/yoCDG/

【讨论】:

    【解决方案2】:

    简短的回答,不。

    CSS(Sass 编译成的)是一种表示语言,它不知道页面的内容。

    最好的选择是用一个 css 类来装饰你想要样式化的所有字段,然后只使用那个 css 类。

    如果您想通过 JQuery 设置这些类,我认为您正在寻找的代码是这样的: $('a:contains("Hello")').addClass('helloStyle');

    正如 ewcz 所评论的,这里是一个重复问题的链接。 Is there a CSS selector for elements containing certain text?

    【讨论】:

      猜你喜欢
      • 2020-09-03
      • 2023-02-21
      • 1970-01-01
      • 2013-01-30
      • 2019-06-03
      • 1970-01-01
      • 2018-05-16
      • 2013-12-29
      • 2014-05-15
      相关资源
      最近更新 更多