我有一个 HTML 文件,我正在加载到 JTextPane 中,其中包含两个我试图并排显示的 DIV(使用 CSS float
)。但是,无论我尝试什么,都行不通。 instructions
元素始终显示在 title
元素下方。我也试过调整宽度。 JTextPane 是否不支持此 CSS 属性 - 我必须使用表格吗?该文件在 Safari 中正确显示。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
@font-face {
font-family: Mentone;
src: local(Mentone),
url(Mentone.otf) format("opentype"),
}
div#container { width: 95%; margin: 0px auto; }
div#title { font-family: Mentone; font-size: 108px; width: 200px; margin: 100px 15px 0 15px; float: left; }
div#instructions { font-family: Mentone; font-size: 130%; width: 300px; margin: 100px 15px 0 15px; color: #dddddd; }
</style>
<title>Welcome</title>
</head>
<body>
<div id="container">
<div id="title">my app</div>
<div id="instructions">Instructions go here.</div>
</div>
</body>
</html>
最佳答案
Swing 中的 HTML 支持充其量只能支持 HTML3.2。因此很可能您想要执行的操作不受支持。
which contains two DIVs I am trying to show side-by-side (using CSS float).
如果您可以控制 HTML,请尝试并排显示两个单独的 JTextPanes,每个 JTextPanes 都包含单独的 HTML。可以将两个文本 Pane 添加到一个面板,并将该面板添加到一个滚动 Pane ,以便它们同步滚动。
关于java - JTextPane 中的 float DIV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2302560/