在一页中显示单独的表

时间:2016-11-07 14:19:38

标签: python html html-table space spacing

我是HTML新手,我在这方面使用Python。

我有一些单独的HTML"对象"我想一个接一个地展示,我需要一个空间。

这是我在网上看到的一个例子:

enter image description here

在这里,我们可以看到3个不同的HTML"对象"我们可以看到它们之间的空间。

如何在一个页面上显示它们?

我的代码:

def nlist_to_html(kpi_data_dict):

    headers_lists = ['Total Revenue'] 
    htable = '<br> <table bordercolor=000000 cellspacing="0" cellpadding="1" ' \
             'style="table-layout:fixed; background: #F5F5F5; vertical-align:bottom; font-size:15px;font-family:verdana,sans,sans-serif;border-collapse:collapse;border:3px solid rgb(12, 73, 173); color:rgb(20, 99, 226)" >'

    for header in headers_lists:
        new_header = '<header> <h1> <th bgcolor = "#777" colspan = "6" align = "left" valign = "center"> <font size = "6" color ="white"> {header} </font> </th> </h1> </header>'.format(header= header)
        htable += new_header

        for row in kpi_data_dict:
            newrow = u'<tr>'
            newrow += u'<td align="left" style="padding:1px 4px">' + unicode(row[1][1]) + u'</td>'
            newrow = newrow + ''.join([u'<td align="center" style="padding:1px 4px">' + unicode(x) + u'</td>' for x in row])
            newrow += '</tr>'
            htable += newrow
        htable += '</table>'

    return htable

1 个答案:

答案 0 :(得分:0)

我不确定,你在这个后端脚本中使用了哪种语言,但试试这个:

def nlist_to_html(kpi_data_dict):
headers_lists = ['Total Revenue'] 
htable = '<br> <table bordercolor=000000 cellspacing="0" cellpadding="1" ' \
         'style="table-layout:fixed; background: #F5F5F5; vertical-align:bottom; font-size:15px;font-family:verdana,sans,sans-serif;border-collapse:collapse;border:3px solid rgb(12, 73, 173); color:rgb(20, 99, 226)" >'

for header in headers_lists:
    new_header = '<tr> <th bgcolor = "#777" colspan = "6" align = "left" valign = "center" style="margin-top:15px;"> <header> <h1> <font size = "6" color ="white"> {header} </font> </h1> </header> </th> </tr>'.format(header= header)
    htable += new_header

    for row in kpi_data_dict:
        newrow = u'<tr>'
        newrow += u'<td  align="left" style="padding:1px 4px; margin-top:15px;">' + unicode(row[1][1]) + u'</td>'
        newrow = newrow + ''.join([u'<td align="center" style="padding:1px 4px; margin-top:15px;">' + unicode(x) + u'</td>' for x in row])
        newrow += '</tr>'
        htable += newrow
    htable += '</table>'

return htable