html - 如果我想隐藏我的文本区域,我该怎么做?

标签 html css

如果我想隐藏我的文本区域,我该怎么做?

最佳答案

每个人都在给你答案,但原因不多。给你:如果你使用 CSS 规则 visibility:hidden; 文本区域将不可见,但它仍然会占用空间。如果您使用 CSS 规则 display:none; textarea 将被隐藏并且它不会在屏幕上保留空间 - 没有间隙,换句话说,它会在哪里已经。下面的可视化示例。

所以你希望这样的东西完全隐藏:

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

例子

/* no styling should show up for either method */
textarea {
  background: lightblue;
  border: 1px solid blue;
  font-weight: bold;
}
<p><strong>Textarea (not hidden)</strong></p>
<textarea>Text within.</textarea>
<p>Some text after.</p>

<hr />

<p><strong>Textarea with <code>display:none;</code></strong></p>
<textarea style="display:none;">Text within.</textarea>
<p>Some text after. Neither height nor margin/padding/layout kept. No other styles visible.</p>

<hr />

<p><strong>Textarea with <code>visibility:hidden;</code></strong></p>
<textarea style="visibility:hidden;">Text within.</textarea>
<p>Some text after. Height and margin/padding/layout kept. No other styles visible.</p>

关于html - 如果我想隐藏我的文本区域,我该怎么做?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2362498/

相关文章:

html - 如何使用 twitter bootstrap 减小 CSS 中的 div 大小?

HTML: Display:none 这是否允许具有相同名称的多个 ID 属性(当 "hidden"时)?

javascript - 对象不支持属性或方法 'push'

html - 如何使用 bootstrap 4 将单选按钮放在行的右端?

html - 如何安抚 Chrome 的输入显示(图像和文本输入)?

css - 使用主题使 Bootstrap 3 导航栏透明

html - 如何使用 css 按类或 id 选择所有子元素?

html - 背景图像推到右边

javascript - 从数据库中排序选择框选项

javascript - 将数组值添加到 Bootstrap 表