如何用CSS隐藏HTML元素? [英] How To Hide An HTML Element With CSS?

查看:121
本文介绍了如何用CSS隐藏HTML元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用CSS隐藏HTML元素.

I am trying to hide an HTML element with CSS.

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

但是它非常有弹性,即使使用Google Inspect元素,我也无法更改样式

but its very resilient, even with 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隐藏HTML元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆