如何从<pre> without leaving an empty line?

时间:2017-03-22 18:38:38

标签: html css display pre

Given a <pre> containing multiple <span>s, how would you remove one of those <span>s without leaving an empty row?

span {
    background-color: blue;
}
#text2 {
    display: none;
}
<pre>
    <span id="text1">SOME RANDOM TEXT</span>
    <span id="text2">SOME RANDOM TEXT</span>  
    <span id="text3">SOME RANDOM TEXT</span>
</pre>

I've tried switching to a <div> and using white-space but that doesn't get the same result.

1 个答案:

答案 0 :(得分:1)

设置pre white-space:nowrap并将span显示设置为table或block

&#13;
&#13;
pre{
      white-space:nowrap;/* nowrap or normal will give you same output*/
}
span {
    display:table;/* use table for same output. you can try display block also */
    background-color: blue;

  
}
#text2 {
    display: none;
}
&#13;
<pre>
 <span id="text1">SOME RANDOM TEXT</span>
 <span id="text2">SOME RANDOM TEXT</span>  
 <span id="text3">SOME RANDOM TEXT</span>
</pre>
&#13;
&#13;
&#13;

相关问题