我有一个使用theater.js将自己擦除并打字的h1和h3标签。问题是,当它自己清空时,所在div的高度会变小,然后当它再次有内容时,会突然变大。
我想让h1和h3标签(或完全更改标签)即使为空也保持其高度。
你有任何想法吗?
我想让h1和h3标签(或完全更改标签)即使为空也保持其高度。
你有任何想法吗?
只需将您的h2 / h3标签放在一个带有display: inline-block;
的div中,就像这样:
<div class="header2"><h2>ABCD</h2></div>
然后将以下内容添加到你的CSS中:
.header2 {
min-width: 100px;
width: auto;
min-height:45px;
background-color:#333;
color:#FFF;
display:inline-block;
padding:10px;
}
em
值而不是固定像素值。 - Paulie_D有两种可能的解决方案:
1)您可以将最小高度设置为div
例如:
div{min-height:50px;}
2) 或者设置 h2 和 p1 标签的最小高度
h1,p1 {
min-height:5px;
}
第二种方法的演示:
h1{
background:yellow;
min-height:5px;
}
<h1></h1>
注意:正如 paulie_D 提到的那样,h1、p和div默认是块级元素。
text-indent
将其滑动出去。
h1.fixed:before {
content:' ';
display:inline-block;
width:1em;
}
h1 {
background:lightgray;
box-shadow:inset 0 0 0 1px;
}
h1.fixed {
text-indent:-0.8em; /* swip off the pseudo element */
}
<h1 contenteditable="true"></h1>
<h1 class="fixed" contenteditable="true"></h1>
h1:empty:before {
content:'|';
}
<h1 contenteditable="true"></h1>
。这个实体会被渲染成一个空格。这样可以隐藏元素,但仍然占据所需的垂直空间。希望这不会混淆屏幕阅读器(对于盲人用户来说)。