【问题标题】:enable disable font-awesome icon启用禁用字体真棒图标
【发布时间】:2017-02-05 15:48:45
【问题描述】:

我有向下箭头字体 - 很棒的图标。由于某些验证原因,我尝试禁用该图标。但是当我给出一个选项'禁用'时,它不起作用。

<div class="arrow bounce text-center" >
     <div class="fa fa-arrow-circle-down fa-3x " style="padding-bottom: 2px;" disabled="disabled"></div>
</div>
.arrow {
    text-align: center;
    margin:40px 0px;
}
.bounce {
    -moz-animation: bounce 2s infinite;
    -webkit-animation: bounce 2s infinite;
    animation: bounce 2s infinite;
}
@keyframes bounce {
    0%,
    20%,
    30%,
    40%,
    50% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-30px);
    }
    50% {
        transform: translateY(-15px);
    }
}

我的代码有什么问题?

【问题讨论】:

  • disabled 对 div 有什么作用?这是input 的属性,而不是 div。 另外,div 没有hrefs。你想做什么?
  • 尝试禁用字体图标。所以使用了禁用的属性。但它不起作用。
  • 不会,它不是适用于 div 的属性。再加上您的 HTML 和 CSS 不匹配。
  • 您似乎遗漏了一些信息/代码。您有 CSS 动画,但没有看到它们被应用到您的 HTML。这是如何实现的?

标签: javascript css html


【解决方案1】:

问题是禁用属性用于输入、按钮或锚元素。您正在尝试在 div 中设置“禁用”。 只需更改:

<div class="fa fa-arrow-circle-down fa-3x custom-color" href="#" style="padding-bottom: 2px;" disabled="disabled"></div>

与:

<a class="fa fa-arrow-circle-down fa-3x custom-color" href="#" style="padding-bottom: 2px;" disabled="disabled"></a>

编辑:

我的错。 Disabled attr 不适用于锚点。检查this。 防止点击锚点的唯一方法是通过 JavaScript。但是您遇到的这个问题与字体真棒图标无关

【讨论】:

【解决方案2】:

工作但不符合 W3C:

.fa[disabled] {
    display: none !important;
}

但是,“禁用”属性与 "div" tag 不兼容 W3C,您必须改用 CSS 类,并在禁用与否时使用 JavaScript 切换它。

这是一个例子:

.fa.disabled {
  display: none !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-T8Gy5hrqNKT+hzMclPo118YTQO6cYprQmhrYwIiQ/3axmI1hQomh7Ud2hPOy8SP1" crossorigin="anonymous">
<button onclick="$('#AppleLogo').toggleClass('disabled');">Pop/unpop Apple</button>
<br/>
<i id="AppleLogo" class="fa fa-apple fa-3x" aria-hidden="true"></i>

多种解决方案:

  • display: none !important;font-size: 0px !important; 进行相同的渲染。该元素似乎未从页面呈现。在这种情况下,!important 很重要,它优于 FontAwesome 类。
  • visibility: hidden; 有点不同,因为元素仍然被渲染,但它是透明的。 color: transparent !important; 在这种情况下也同样有效。它保持相同的位置和空间。

可选:如documentation中所述,FontAwesome 用于“i”标签中

【讨论】:

  • disabled 属性和它使用的元素已经由 cmets 处理到 OP 的问题和答案。 FontAwesome 使用 &lt;i&gt; 但不是必需的,它与许多其他元素一样是内联元素。我建议您更新您对切换 CSS 类的建议的回答。
  • 嗨!我更新了我的评论,添加了一个 sn-p 并解释了不同的解决方案。我只是在向他解释他应该如何编码,而不是提供复制粘贴解决方案。我知道&lt;i&gt; ...只是为了更好地使用而显示。我希望你会喜欢:)
猜你喜欢
相关资源
最近更新 更多
热门标签