【问题标题】:A tag class not working标记类不起作用
【发布时间】:2012-07-05 17:43:04
【问题描述】:

我有一个要添加类的 A 标签。这可能是非常简单的事情,但我以前从未这样做过。

<a class="button" href="landscaping.html">Find out more about our landscape design services</a>

还有 CSS:

a .button{
color:#7cc242;
font-family: 'PTSansNarrowBold';
font-size:18px;
margin-top: 7px;
margin-bottom: 0px;
text-align:right;
text-decoration:none;
display: inline-block;
zoom:1;
*display:inline;
padding-right:30px;
background:url(images/more-btn.png) no-repeat top right;}

似乎没有任何效果,我只是得到标准的蓝色。有人可以帮忙吗?

【问题讨论】:

    标签: html css hyperlink tags


    【解决方案1】:

    不应该有空格!请更改:

    a .button{
    

    到:

    a.button{
    

    在这里查看小提琴:http://jsfiddle.net/VhaNQ/

    【讨论】:

    • 非常感谢! D'oh - 我知道这将是那些愚蠢的问题之一。感谢您帮助我看到令人眼花缭乱的事实!
    【解决方案2】:

    您在 CSS 中所说的是“我希望所有 button 类的 children 以及所有 a 标记都使用下一个 CSS 规则”。

    你需要说的是“我想用 button 类标记 a 以使用下一个 CSS 规则”。

    这是通过编写下一个 CSS 来实现的:

    a.button{
      color:#7cc242;
      font-family: 'PTSansNarrowBold';
      font-size:18px;
      margin-top: 7px;
      margin-bottom: 0px;
      text-align:right;
      text-decoration:none;
      display: inline-block;
      zoom:1;
      *display:inline;
      padding-right:30px;
      background:url(images/more-btn.png) no-repeat top right;
    }
    

    请注意,a.button 之间没有空格

    标签/类/ids之间的空格表示“元素的子元素”。

    祝你好运:)

    【讨论】:

      【解决方案3】:

      a .button 中删除空格,像这样a.button 或简单地使用.button

      【讨论】:

        猜你喜欢
        • 2017-10-03
        • 1970-01-01
        • 2016-05-05
        • 2018-12-31
        • 1970-01-01
        • 1970-01-01
        • 2019-01-16
        • 2013-02-27
        相关资源
        最近更新 更多