简体   繁体   中英

Django textfield stretches the width of an html table? How can I prevent this?

I have a django table that's supposed to display the contents of each field of a model called Resource I wrote it like this, with results being a part of the contexts dictionary and simply containing filtered Resource objects.

      <table style="width: 70%;">
  <tr>
     <th>Title</th>
     <th>Author</th>
     <th>Country</th>
     <th>Description</th>
  </tr>
{% for resource in results %}
  <tr>
     <td><a href="{{ resource.link }}">{{ resource.title }}</a></td>
     <td>{{ resource.author }}</td>
     <td>{{ resource.country }}</td>
     <td>{{ resource.description }}</td>
  </tr>

{% endfor %}

The basic html table that created currently gets to dimensions of around 1500 x 3200. Pretty big, but that's not because my monitor is big or something like that. As a matter of fact, even if I had the css style set as width: 70% attribute or anything of that sort, the dimensions of the table do not change.

If I get rid of the following line, <td>{{ resource.description }}</td> which is supposed to display the Resource model's textfield known as "description", however, then then I can actually customize the width of the table and prevent it from being so long.

I need to be able to shorten the width of the table, and particularly this field. What can be done?

Try adding css for the description <td> .

stye="overflow-x: scroll; width: 300px;"

That way no matter how long is the description it won't stretch the table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM