【问题标题】:Django/html table: Description inside header row shifts to the rightDjango / html表:标题行内的描述向右移动
【发布时间】:2011-09-19 10:45:39
【问题描述】:

我好像也遇到了奇怪的问题。

我有一个 django 应用程序,可以从表单中创建注释。从此表单输入的所有这些注释都存储在表格列表中。像这样。

<div style="overflow:auto; height:100px; width:721px; padding:12px; border:1px solid #C0C0C0">
{% for note in notes %}
        <table style="border:1px solid #C0C0C0">
        <tr><th >{{note.datetime}} {{note.datetime.time}} - Posted by {{note.user}}</th></tr>
        <tr><td>{{ note.note}}</td></tr>
        </table>
{% endfor %}
</div>

如您所见,第一行将打印用户名、日期和时间。第二行产生那个音符。问题是,如果我创建一个长度很长的便笺,(很多字)第一行开始向右移动更多。我不希望这种情况发生。无论您为笔记输入多少单词和字母,我如何才能让标题行停留在左侧?

【问题讨论】:

    标签: python html css django html-table


    【解决方案1】:

    默认情况下 a th 将其文本居中。所以你应该把它左对齐:

    <tr><th style="text-align: left">{{note.datetime}} {{note.datetime.time}} - Posted by {{note.user}}</th></tr>
    

    当然,我也有义务告诉你,应该避免向这样的标签添加样式属性。确实,您的 css 应该存在于一个单独的文件中,但显然这对您现有的问题没有帮助。

    【讨论】:

    • 这似乎解决了这个问题。我会记得把它放在一个单独的 css 文件中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-18
    • 1970-01-01
    • 1970-01-01
    • 2020-11-24
    • 2021-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多