[英]How to remove underline from a link and add underline on hover? (images attached)
[英]How to remove underline from the link which has number but keep underline on normal link which has alphabets
請告訴我如何從帶有數字的鏈接中刪除下划線,而在具有字母的普通鏈接上保持下划線?
我在這里創建了一個演示,但不確定如何執行此操作
a{ text-decoration:underline; } /* TODO - Write code either with CSS or JS for the anchors which has text as number to NOT to have underline */
<a href="#">Login</a> <a href="#">1111</a> <a href="#">2222</a> <a href="#">aavv1111</a>
CSS無法確定元素的內容是否為數字,因此您將需要使用JS。
您可以嘗試將每個元素的文本內容解析為整數。 如果可行,請刪除下划線,否則保留該下划線。 嘗試這個:
$('a').css('text-decoration', function(){ return isNaN(parseInt($(this).text(), 10)) ? 'underline' : 'none'; });
a { text-decoration: underline; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <a href="#">Login</a> <a href="#">1111</a> <a href="#">2222</a> <a href="#">aavv1111</a>
如果您的內容不是動態或更新的,則可以在不想加下划線的鏈接上添加其他類。
a { text-decoration: underline; } a.nounderline { text-decoration: none; }
<a href="#">Login</a> <a href="#" class="nounderline">1111</a> <a href="#" class="nounderline">2222</a> <a href="#">aavv1111</a>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.