How To Hide An HTML Element With CSS? [closed]

蹲街弑〆低调 提交于 2019-12-17 16:50:42

问题


I am trying to hide an HTML element with CSS.

<select id="tinynav1" class="tinynav tinynav1">

but its very resilient, even with Google Inspect element I cannot change the styling

Any ideas?

Thank you :-)


回答1:


It's simple, just set the display property to none in CSS:

#tinynav1
{
  display:none
}

again when you would like to show it set the display to block.

visibility: hidden hides the element, but it still takes up space in the layout.

display: none removes the element completely from the document. It does not take up any space, even though the HTML for it is still in the source code.

Other advantages of using display:

display:none means that the element in question will not appear on the page at all (although you can still interact with it through the DOM). There will be no space allocated for it between the other elements.
visibility:hidden means that unlike display:none, the element is not visible, but space is allocated for it on the page.




回答2:


use display:none; or visibility:hidden;




回答3:


CSS:

select#tinynav1  { display: none; }

or if multiple selects should be hidden, use the corresponding class:

select.tinynav1  { display: none; }

As inline-style you could do it also (which you can try for inspector):

<select id="tinynav1" style="display: none">



回答4:


You can use display:none or visibility:hidden, based on your requirements:

#tinynav{display:none;}

or

 #tinynav{visibility:hidden;}

Refer the below URL for better understanding of display:none and visibility:hidden.

Difference between "display:none" and "visibility:hidden"




回答5:


If you want to hide it and collapse the space it would need, use display: none; if you want to keep the space, use visibility: hidden.

<select id="tinynav1" class="tinynav tinynav1">

CSS

.tinynav {
    display: none;
}



回答6:


Use style="display:none" directly on the <select> or create a css class having that setting and assign the class to the <select>.




回答7:


Use this CSS

.tinynav {
    display: none;
}

or

.tinynav {
    visibility: hidden;
}

The difference is that the former will make the select not rendered at all and the latter will make the select rendered (it will take the space of the document) but it will be completely invisible;

Here's a fiddle to show the difference: http://jsfiddle.net/rdGgn/2/
You should notice an empty space before the text in third line. It is the select that is rendered but not visible. There is no space before the second line of text, because the select is'nt rendered at all (it has display:none).

There is also a third option which is

.tinynav {
    opacity: 0;
}

It behaves almost the same as visibility: hidden but the only difference is that with opacity: 0 you can still click the select. With visibility: hidden it is disabled.



来源:https://stackoverflow.com/questions/19400139/how-to-hide-an-html-element-with-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!