【发布时间】:2017-02-18 19:52:27
【问题描述】:
以下代码将使用 CSS 将具有交替行颜色的表格写入 html 文件。写入磁盘后,直接查看 html 文件时,例如Firefox、Chrome、IE 等,交替的行颜色可见。但是,在 VS2015 中,将 html 文件加载到 WebBrowser1 控件后,交替的行颜色不可见。
我检查了 SO 和其他地方的其他帖子,很明显 WebBrowser 只是包装了 IE,为了克服 WebBrowser 的问题,有一些解决方法涉及安装 3rd 方开源。但是,MS 为这个问题提供的直接解决方案怎么样?对于 MS 和 VS2015,这似乎是一个未开发的问题,因为这意味着与 VS2015 捆绑的当前控件存在 CSS 问题。有任何基于 MS 的解决方案吗?
Dim sw As New StreamWriter(filename)
sw.WriteLine("<!DOCTYPE html><html><body>")
sw.WriteLine("<style type=" & """" & "text/css" & """" & ">")
sw.WriteLine("table.gridtable {")
sw.WriteLine(" font-family: verdana,arial,sans-serif;")
sw.WriteLine(" font-size:12px;")
sw.WriteLine(" color: #333333;")
sw.WriteLine(" border-width: 1px;")
sw.WriteLine(" border-color: #666666;")
sw.WriteLine(" border-collapse: collapse;")
sw.WriteLine("}")
sw.WriteLine("table.gridtable th {")
sw.WriteLine(" border-width: 1px;")
sw.WriteLine(" padding: 8px;")
sw.WriteLine(" border-style: solid;")
sw.WriteLine(" border-color: #666666;")
sw.WriteLine(" background-color: #dedede;")
sw.WriteLine("}")
sw.WriteLine("table.gridtable tr {")
sw.WriteLine("background-color: #ffffff;")
sw.WriteLine("}")
sw.WriteLine("table.gridtable tr:nth-child(even) {")
sw.WriteLine("background-color: #fdf5e6;")
sw.WriteLine("}")
sw.WriteLine("table.gridtable td {")
sw.WriteLine(" border-width: 1px;")
sw.WriteLine(" padding: 8px;")
sw.WriteLine(" border-style: solid;")
sw.WriteLine(" border-color: #666666;")
sw.WriteLine("}")
sw.WriteLine("</style>")
sw.WriteLine("<table class=" & """" & "gridtable" & """" & " Align=center>")
sw.WriteLine("<tr>")
sw.Write("<th>" & "Output" & "</th>")
sw.Write("<th>" & "Output" & "</th>")
sw.Write("<th>" & "Output" & "</th>")
sw.Write("<th>" & "Output" & "</th>")
sw.WriteLine("</tr>")
sw.WriteLine("<tr>")
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>")
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>")
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>")
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>")
sw.WriteLine("</tr>")
sw.WriteLine("<tr>")
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>")
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>")
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>")
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>")
sw.WriteLine("</tr>")
sw.WriteLine("<tr>")
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>")
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>")
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>")
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>")
sw.WriteLine("</tr>")
sw.WriteLine("<tr>")
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>")
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>")
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>")
sw.WriteLine("<td align=""center""><font color=" & """" & "#000000" & """" & ">Hello</font></td>")
sw.WriteLine("</tr>")
sw.WriteLine("</table>")
sw.WriteLine("</body></html>")
sw.dispose
【问题讨论】:
标签: css vb.net colors html-table webbrowser-control