[英]Hide an element in a class - where do I add the code to hide the element?
我發現了這篇帖子,幾乎就是我想在自己的Owncloud服務器上完成的帖子- 隱藏類中的第二個元素
從建議的答案(有很多)中,最后一條評論說需要以下內容:
.fileactions > a:nth-child(2) {
display: none;
}
我的問題是...我應該把這段代碼放在哪里? 我不能從答案中看出該放在哪里? 我在Owncloud中有一個.js文件,稱為fileactionsSpec.js。 這是我唯一找到其中帶有動作下載字樣的代碼的地方。 我是否添加以下代碼:
.fileactions > a:nth-child(2) {
display: none;
}
到那個.js文件的末尾?
謝謝。
您不應將其放在JS文件中。 您需要將其添加到CSS文件中,例如: style.css
,並且style.css
文件應引用為:
<link rel="stylesheet" href="style.css" />
上面的代碼必須添加到HTML頁面的<head>
部分。
如果需要僅JS方法,則需要這樣添加它:
var css = '.fileactions > a:nth-child(2) {display: none;}',
head = document.head || document.getElementsByTagName('head')[0],
style = document.createElement('style');
style.type = 'text/css';
if (style.styleSheet){
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
head.appendChild(style);
<div class="fileactions">
<a>This is visible</a>
<a>This is invisible</a> <!--it will hide this one-->
</div>
希望這可以幫助。 請閱讀HTML和CSS的介紹。
把它放在你的css文件中,因為
.fileactions > a:nth-child(2) {
display: none;
}
手段
<div class="fileactions">
<a>This is visible</a>
<a>This is invisible</a> <!--it will hide this one-->
</div>
此代碼是CSS,而不是JavaScript。 您應該將其添加到.css文件中,或添加到頁面本身的標簽中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.