html - Make an HTML element invisible and not take up space in layout
问题描述
I have this:
<div class="pane">
<!-- other elements -->
<textarea class="editor invisible">Start Writing here</textarea>
<div class="v-container visible default background-image">
</div>
The CSS:
.editor {
margin: 0;
overflow: auto;
outline: none;
resize: none;
border: none;
position: relative;
top: 0;
right:0;
bottom: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.007);
padding: 8px 8px 8px 8px;
width: 100%;
height: 100%;
}
.editor::selection {
background-color: rgba(0, 0, 0, 0.164);
}
.default {
background-color: rgba(0, 0, 0, 0.103);
width: 100%;
height: 100%;
pointer-events: none;
}
.background-image {
background-image: url('../graphics/Note.png');
background-position: center;
background-repeat: no-repeat;
}
I want it that when the textarea is visible, the other child element in pane would be invisible and not take up layout space at all. I tried using visibility: hidden
and visibility: visible
but when the textarea is invisible there is still a blank space on the window.
解决方案
您应该使用 display:none 来防止它占用空间。
display: none
推荐阅读
- excel - 用户输入错误密码 3 次后,Excel 工作簿是否可以自毁?
- node.js - lrange 返回 false 而不是列表
- python - 根据属性将两个人匹配在一起
- algorithm - 数论变换递归算法
- python-3.x - Pytorch - Google colaboratory - PIL - 加载批次时操作系统读取错误
- matlab - 存储最大频率
- javascript - 异步向下钻取不更新 HighCharts
- android - Exoplayer 只播放一些.m3u8 链接,其他只是加载时间但不开始播放
- python - 如何使用 Python(lxml、html、requests、xpath)从一个页面获取不同的表?
- pandas - 遍历 Pandas 中的行和列