1

I'm really new to HTML and CSS, so this is probably a really basic question:

Let’s say I have a page where I'm displaying books (with all the information associated with a book- like an image, name, isbn). Sometimes I'll have 1 book, other times I'll have 3 or 6 and so forth.

I know how to display one book using CSS and HTML, but how do I display and position multiple books? I want the first book to appear at the top of the page and subsequent books to appear below it - how do I achieve this?

The information is coming from a database and is on the HTML page through a Django template - so I have template tags like {{ author|safe }} that holds each (in this case) author's name.

This is the code that I have in the Django template:

<html>
<head>
<body>
<h1>Testing the class page backend</h1>

<ul>
{% for edition in editions %}
    <li>{{ edition|safe }}</li>
{% endfor %}
{% for image in images %}
    <li>{{ image|safe }}</li>
{% endfor %}
{% for author in authors %}
    <li>{{ author|safe }}</li>
{% endfor %}
{% for book_title in book_titles %}
    <li>{{ book_title|safe }}</li>
{% endfor %}
</ul>

</body> 

</html>
Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
praks5432
  • 7,246
  • 32
  • 91
  • 156
  • errr, just repeat the code? Can we see an example, maybe code it up in [jsfiddle](http://jsfiddle.net/) – Alex Sep 14 '11 at 09:04
  • how are you displaying your books in page? some script or php or where does that books list come from? – Gatekeeper Sep 14 '11 at 09:05
  • If enclose every book in block elements like
    they will automatically be under each other. If this is what you ask
    – friendzis Sep 14 '11 at 09:12
  • the issue with repeating the code is that I don't know how many books I'm going to have to display- I know I need a for loop and I know how to display one book, I'd like to display all books for which I pass in information with the same formatting, except at a different position – praks5432 Sep 14 '11 at 09:13
  • @praks5432 I notice the inclusion of the 'django' tag now. Is that the technology you're using? – Alex Sep 14 '11 at 09:15
  • yes it is - I added the django template code to help – praks5432 Sep 14 '11 at 09:17
  • In what way does `{% for book in books %}
  • {{ book|safe }}
  • {% endfor %}` **not** display multiple books, one underneath the other? – Paul D. Waite Sep 14 '11 at 09:20
  • sorry- that's badly named- book refers to the name of the book- so the information that comes in at index 0 of all the querysets refers to the first book and needs to be displayed together – praks5432 Sep 14 '11 at 09:24
  • @praks5432: ah, okay. That does seem like a weird way to organise your context data. I’ve posted an answer below discussing that. – Paul D. Waite Sep 14 '11 at 09:29