Html 参数化样式=";利润率顶部:Xem";设置任何X
我想通过从文件中读取的明文来构建。 该文件具有以下外观:Html 参数化样式=";利润率顶部:Xem";设置任何X,html,Html,我想通过从文件中读取的明文来构建。 该文件具有以下外观: Line1 Line3 第2行完全为空,甚至没有空格。 html文件如下所示 <!DOCTYPE HTML PUBLIC><html> <head> <style type='text/css'>#editor { white-space: pre; }</style> </head> <body style="font-family: 'Segoe Pri
Line1
Line3
第2行完全为空,甚至没有空格。
html文件如下所示
<!DOCTYPE HTML PUBLIC><html>
<head>
<style type='text/css'>#editor { white-space: pre; }</style>
</head>
<body style="font-family: 'Segoe Print'; font-size:14pt">
<p id='editor', style=" margin-top:0px; margin-bottom:0px; margin-left:0px">Line1</p>
<p id='editor', style=" margin-top:0px; margin-bottom:0px; margin-left:0px"></p>
<p id='editor', style=" margin-top:0px; margin-bottom:0px; margin-left:0px">Line3</p>
</body></html>
#编辑器{空白:pre;}
第1行
第3行
带有“p id=…”的代码行很重要。它们的中间线将被忽略,因此仅显示两条线。那是因为在结束/p之前没有文本,对吗?我当然可以输入一个“”(空格),但这是一个肮脏的解决方案
我找到了一个折衷的解决方案,在下面的行中插入“margintop:Xem”而不是“margintop:0px”。X是“1”。现在的问题是:
当程序计算出有4个空行时,我如何为X输入任何其他值,例如4
编辑:这是我试过的。没有什么改变
<!DOCTYPE HTML PUBLIC><html>
<head>
<style type='text/css'>p.editor { white-space: pre; min-height:1em; }</style>
</head>
<body style="font-family: 'Segoe Print'; font-size:14pt">
<p class='editor' style=" margin-top:0em; margin-bottom:0px;">Line1</p>
<p class='editor' style=" margin-top:0em; margin-bottom:0px;"></p>
<p class='editor' style=" margin-top:0em; margin-bottom:0px;">Line3</p>
</body></html>
p、 编辑器{空白:pre;最小高度:1em;}
第1行
第3行
有几点:
p
元素显示时不包含任何文本,只需给它一个最小高度即可
第1行
第3行
p.editor{
空白:预处理;
保证金:0;
最小高度:16px;
}
默认情况下,p
元素默认为其中内容的高度。没有内容,就没有高度。指定最小高度意味着空的p
元素将始终具有一定的高度,而不管它是否包含内容
但是,如果希望空行可以复制,则需要修改HTML本身以使用(
)而不是将元素保留为空:
第1行
第3行
这样,您就不需要额外的最小高度,因为不间断的空格与元素的字体大小一致
.解决方案适合我:
<!DOCTYPE HTML PUBLIC>
<html>
<head>
<style type='text/css'>h1 { white-space: pre; min-height:1em; font-family: arial;
font-size:8pt; color:green; margin-bottom:0px; margin-top:0px}
</style>
</head>
<body>
<h1>Line1</h1>
<h1></h1>
<h1>Line3</h1>
</body></html>
h1{空白:pre;最小高度:1em;字体系列:arial;
字体大小:8pt;颜色:绿色;页边距底部:0px;页边距顶部:0px}
第1行
第3行
把它分阶段插入,它就工作了。
如果将其设置为QTextBrowser,则不会。但这是另一个问题,
id='editor',
3个元素的相同id+额外的逗号这是什么意思?我不明白。1)id应该是唯一的2)你需要删除那个逗号,它是不正确的语法是的,好吧,但这与我的问题有什么关系?这是你需要在代码中修复的第一件事。我稍微处理了一下。在我的示例中,我必须将p.editor{min height:1em;margin:0;}放在哪里?啊,我猜在样式部分之间