【问题标题】:how to give boder colors in html table without using style tags如何在不使用样式标签的情况下在 html 表格中赋予边框颜色
【发布时间】:2020-02-19 07:51:44
【问题描述】:

我需要在不使用样式标签的情况下开发一些示例,我主要尝试过,但我无法添加边框和特定于边框的 td 边框,请查看我的代码并帮助我解决此问题。

<table style="width:100%" border='0' cellpadding="0" ><tr cellspacing="0">
<td rowspan='2' > <img  height='100' width='80' src="http://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_1280.jpg" alt=" Logo" /></td>
<td width='500' border='1' bordercolor="red"><b>some text</b></td></tr><tr cellspacing="0">
<td border='1' color='red' >some text
                  </td>
<td> <label> Name: &nbsp;</label><br />
                <label>class: &nbsp;</label><br />
                <label>  ID: &nbsp;</label></td></tr></table>

输出如下所示:

【问题讨论】:

  • 你可以使用类或ID吗? border 之类的属性以及您正在使用的类似属性都已弃用
  • 不使用 CSS 文件是有原因的?
  • @Gonzalo 是的,我正在使用 itextsharp 生成 pdf,因为内联样式无法识别,所以只需要像这样开发,我可以选择 loadstyles,但它会影响剩余的 pdf。所以请帮我解决这个没有 style 关键字(内联样式)的输出
  • @Daniel 类也可以。你能帮我解决这个输出吗
  • 如果你可以使用类,那么在内部样式的帮助下它会更简单,当你生成 PDF 文件或者你想要简单的 html 然后使用 bordercolor="#ff0000" 在表格中。

标签: html user-interface


【解决方案1】:

如果支持您的PDF generation tool 内部样式,请在类的帮助下使用内部样式

<style type="text/css">
.my-table{border-collapse:separate;width:100%;}
.my-table td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
/*Below border color defined*/
.border-black{border-color: #000000;}
.border-green{border-color: #00ff00;}
.border-red{border-color: #ff0000;}
.border-blue{border-color: #0000ff;}
/*Below text color defined*/
.text-green{color: #00ff00;}
</style>

<table class="my-table" cellspacing="10" cellpadding="0">
  <tr>
    <td class="border-red" rowspan="2" width="80">
    	<img  height='100' width='80' src="http://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_1280.jpg" alt=" Logo" />
    </td>
    <td class="border-black text-green">Some text with black border and green text color</td>
    <td class="border-blue" rowspan="2">
    	<label>Name: &nbsp;</label><br />
        <label>Class: &nbsp;</label><br />
        <label>ID: &nbsp;</label>
    </td>
  </tr>
  <tr>
    <td class="border-green text-green" width="400">
    	Some text with green border & green text color
    </td>
  </tr>
</table>

【讨论】:

    猜你喜欢
    • 2017-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-02
    • 1970-01-01
    • 2015-08-14
    • 2013-11-09
    • 1970-01-01
    相关资源
    最近更新 更多