通过CSS隐藏元素的可能方法是什么 [英] What are the possible ways to hide an element via CSS
问题描述
我正在尝试使用CSS隐藏HTML元素.
I am trying to hide an HTML element with CSS.
<select id="tinynav1" class="tinynav tinynav1">
但是它非常有弹性,即使使用Google Inspect元素,我也无法更改样式.
but it's very resilient, even with the Google Inspect element I cannot change the styling.
推荐答案
很简单,只需在CSS中将display
属性设置为none
:
It's simple, just set the display
property to none
in CSS:
#tinynav1
{
display:none
}
再次显示
时,将display
设置为block
.
visibility: hidden
隐藏该元素,但它仍然占用布局中的空间.
visibility: hidden
hides the element, but it still takes up space in the layout.
display: none
将元素从文档中完全删除.即使它的HTML仍在源代码中,它也不会占用任何空间.
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.
使用display
的其他优点:
display:none
意味着所讨论的元素根本不会出现在页面上(尽管您仍然可以通过DOM与之交互).其他元素之间将没有分配空间.
visibility:hidden
表示与display:none
不同,该元素不可见,但在页面上为其分配了空间.
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.
这篇关于通过CSS隐藏元素的可能方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!