【问题标题】:CSS class not applying toCSS类不适用于
【发布时间】:2017-12-19 13:16:37
【问题描述】:

我想将 CSS 类 washes_times_links 应用于下面的 html,但由于某种原因它不起作用。

.washes_times_links a {
  display: block;
  padding: 15px;
  padding: 13px;
  text-align: center;
  color: #3b524b;
  font-size: 15px;
  text-transform: capitalize;
}

.washes_times_links a:nth-child(odd) {
  background-color: #fff;
}

.washes_times_links a:last-child {
  border-radius: 0 0 5px 5px
}

.washes_times_links a:hover {
  color: #fff;
  background-color: #12be9c;
}
<p class="washes_times_links">
  <a href="http://hairactivation.com/male-hairloss-treatment/#wash-hair-less-5-days-week">1 time a week</a>
  <a href="http://hairactivation.com/male-hairloss-treatment/#wash-hair-less-5-days-week">2 times a week</a>
</p>

【问题讨论】:

  • 我刚刚将您的示例代码转换为 StackSnippet,它工作正常。您确定您正确加载了 CSS 文件吗?
  • 这在什么方面不起作用,规则似乎在您的示例中按预期应用?
  • “不工作”不是问题的技术描述。

标签: html css class


【解决方案1】:

看起来不错。 检查这里的 css 属性:[https://jsfiddle.net/nf0a5gq7/][1],您会看到所有 css 属性都已应用,但是您缺少“border”属性(在 .washes_times_links a:last-child 中),这就是您可以的原因看不到边界..

【讨论】:

    【解决方案2】:

    一般来说,对经过这里的人有用。

    在奇/偶选择器中应用样式:

    .class_name a:nth-child(odd) {
      background-color: #ffff99;
    }
    .class_name a:nth-child(even) {
      background-color: #b8d1f3;
    }
    

    为第一个/最后一个选择器应用半径/样式:

    .class_name a:first-child {
        border-radius: 5px 5px 0 0;
    }
    .class_name a:last-child {
        border-radius: 0 0 5px 5px;
    }
    

    大家一起:

    HTML

    <p class="class_name">
        <a href="#1">1st row</a>
        <a href="#2">2nd row</a>
        <a href="#3">3rd row</a> 
        <a href="#4">4th row</a> 
    </p>
    

    CSS

    .class_name a {
        /* default links styles */
    }
    .class_name a:nth-child(odd) {
      background-color: #ffff99;
    }
    .class_name a:nth-child(even) {
      background-color: #b8d1f3;
    }
    .classname a:first-child {
        border-radius: 5px 5px 0 0;
    }
    .class_name a:last-child {
        border-radius: 0 0 5px 5px;
    }
    .class_name a:hover {
        color: #fff;
        background-color: #12be9c;
    }
    

    Tip: How do I ask a good question?

    【讨论】:

    • 这是在回答他的问题吗?
    • @Rob,我相信是的。等待提问者的反馈
    猜你喜欢
    • 2016-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-02
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 2016-07-16
    相关资源
    最近更新 更多