2010-03-02 89 views

回答

2

使用CSS可见性属性应该做的伎俩。

3

用css:display: none;(这将使textarea的完全消失,它通常会占用空间不会被保留)

+0

我有这样的代码 怎么做我设置为隐藏 – nisnis84 2010-03-02 10:52:39

+0

您可以添加样式= “显示:无”。正如@thelost所说,你也可以做style =“visibility:hidden”。这将使textarea仍占用页面上的空间。你应该真的把它放在样式表中。这意味着将class =“hidden”添加到textarea-tag并添加textarea.hidden {display:none; }到你的css文件 – Rune 2010-03-02 10:53:47

5

您有几种选择,这里有一些例子:

  1. 显示:无
  2. visibility:hidden的

下面是一些示例代码,让你看到自己

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title>Text Area Hidden</title> 
    <style type="text/css"> 
     .hideButTakeUpSpace 
     { 
      visibility: hidden; 
     } 

     .hideDontTakeUpSpace 
     { 
      display:none; 
     } 

    </style> 

</head> 
<body> 
    <h1>Text area hidden examples</h1> 
    <h2>Hide but take up space (notice the gap below)</h2> 
    <textarea class="hideButTakeUpSpace" rows="2" cols="20"></textarea> 

    <h2>Hide Don't take up space</h2> 
    <textarea class="hideDontTakeUpSpace" rows="2" cols="20"></textarea> 


</body> 
</html> 

看到这个jsFiddle Example

+1

为什么downvote? – 2014-07-28 07:50:30

32

每个人都在给你答案,但没有太多的理由。在这里你会发现:如果你使用CSS规则visibility:hidden;,文本区域将不可见,但它仍然占用空间。如果您使用CSS规则display:none;,textarea将被隐藏它不会在屏幕上保留空间 - 换句话说,它不会出现间隔。这里有一个很好的视觉例如:http://www.w3schools.com/css/css_display_visibility.asp

为了把样式规则在您的textarea的,你想是这样的:

<textarea cols="20" rows="20" style="display:none;"> 
2

隐藏占据当前网页的空间。

<textarea style="visibility:hidden"></textarea> 

消失在当前网页上,没有其他影响。

<textarea style="display:none" ></textarea> 
0
<!DOCTYPE html> 
<html> 
<head> 
<style> 
textarea.none { 
    display: none; 
} 

textarea.hidden { 
    visibility: hidden 
} 

</style> 
</head> 
<body> 

<textarea class="none">The display is none.</textarea> 
<br> 
<textarea class="hidden">visiblity is hidden</textarea> 
<br> 
<textarea >This is visible and you can see a space taken visiblity:hidden</textarea> 
</body> 
</html> 
相关问题