Forum Moderators: not2easy

Message Too Old, No Replies

Having Item name above thumbnails

Wondering how to display text directly above a row of small images

         

amdowney

5:50 pm on Jul 12, 2007 (gmt 0)

10+ Year Member



Hi,

Am new here so hello!

Am learning CSS structure now so no tables, I am wondering what is the best way to have a row of small images for product thumbs with text above each one as the name?

Thanks in advance!

DrDoc

5:57 pm on Jul 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perhaps use a table with a <th> for each item name, and the thumbnail inside a <td> below it?

[edited by: DrDoc at 5:57 pm (utc) on July 12, 2007]

Marshall

7:21 pm on Jul 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



amdowney,

Without knowing exactly how your page is laid out, I can only provide general options. However, if you are doing away with tables and using purely CSS, you could display each thumbnail in a <div>
<style type="text/css">
#thumbnail {
font: arial .8em #000;
}
</style>

<div id="thumbnail:>
Text<br />
thumbnail
</div>

-or-

You can use a <p> elements and assign it inline (which may be the better option):

<style type="text/css">
#inline p {
display: inline;
font: arial .8em #000;
}
</style>

<div id="inline">
<p>Text 1<br />
thumbnail 1</p>
<p>Text 2<br />
thumbnail 2</p>
And so on....
</div>

Marshall

I WAS IN ERROR! Wrong element. See the post below. It does work.

[edited by: Marshall at 8:01 pm (utc) on July 12, 2007]

DrDoc

8:01 pm on Jul 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No need to "do away" with tables for perfectly acceptable use of tabular data, though ;)

Marshall

8:04 pm on Jul 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This does exactly what you want. Set the #inline span width to the minimum width of your thumbnail. Sorry about the previous boo boo.

Marshall

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Text 1 thumbnail 1</title>
<style type="text/css">

#inline ul {
list-style:none;
}
#inline li {
font: arial .8em #000;
text-align: center;
}
#inline span {
float:left;
display:block;
width: 100px;
text-align: center;
}
</style>
</head>

<body>

<div id="inline">
<ul>
<li><span>Text 1</span> <span>TEXT 2</span>
</li>
<li><span>thumbnail 1</span>
<span>thumbnail 2</span></li>
</ul>
</div>

</body>

</html>

DrDoc

9:06 pm on Jul 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No offense ... but I stand by my table recommendation. Even though Marshall's suggestions may look the way you want, they are semantically out the window. Especially the list suggestion. ;)

Another option, if you really don't want to use a table, is something like this:

span, img {
float: left;
}
span {
width: 100px;
}
img {
margin-left: 100px;
}

<span>Item name</span><img>
<span>Item name</span><img>

Make sure the span is the same width as the image ... and that the margin-left for your image is equal to its own width.

Marshall

9:11 pm on Jul 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



they are semantically out the window

Granted. It was just a suggestion. You can also do it using <p> which is more correct and less code.

<p><span>TEXT</span><span>TEXT</span><span>TEXT</span><br />
<span>IMAGE</span><span>IMAGE</span><span>IMAGE</span></p>

Just set the span width with text-align: center.

Marshall

DrDoc

9:24 pm on Jul 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, the p/span approach is a much better and preferrable solution :)

Marshall

9:37 pm on Jul 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I try Doc. Doing too many things at once - mind wonders ;)

Marshall

DrDoc

9:42 pm on Jul 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Of course, if everything has a fixed size (which it almost has to have), you can play with positioning and stuff too.

penders

11:44 pm on Jul 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Ok, I bite...

No need to "do away" with tables for perfectly acceptable use of tabular data, though ;)

Tabular data?! Have you been sniffing the meta tags? A matter of opinion may be, but who can deny that it's a list of products!? ;)

Marked up as a list and styled accordingly - although keep the text description and image together in the same list item. They naturally go together so should stay together - nice and cosy.

Apart from an appropriately marked up list being (in my opinion) semantically sound in this case, the other graphical advantage of a list is that it will naturally flow to fit your container (as long as the text and image are together). If there isn't enough room on the row for all your products (may be the user resizes their browser, enlarges the text, or is using their phone...?!) then the list items will flow onto the next line and so on. A table is a fixed number of columns wide (as defined by the markup) - if it doesn't fit, it doesn't fit! (Although it is implied that 'a' row is reqd?!)

Anyway, an idea for this code might be...

First, decide how the HTML should be:

<div class="products"> 
<ul>
<li><div>Product Name 1</div><img src="img/product1.jpg" alt="Product Info 1"></li>
<li><div>Product Name 2</div><img src="img/product2.jpg" alt="Product Info 2"></li>
<li><div>Product Name 3</div><img src="img/product3.jpg" alt="Product Info 3"></li>
<li><div>Product Name 4</div><img src="img/product4.jpg" alt="Product Info 4"></li>
<!-- etc... -->
</ul>
</div>

Then CSS accordingly:

.products ul { 
list-style:none; /* No bullets */
overflow:hidden; /* Clear the floats */
}
.products li {
float:left; /* Horiz list */
width:180px; /* Room for thm and text */
padding:10px; /* Gap between */
}
.products li div {
text-align:center; /* Centre description */
}
.products li img {
display:block;
margin:0 auto; /* Centre block image */
width:150px; /* All thms the same size */
height:150px;
}

... with a Transitional OR Strict DOCTYPE.

Just to add, you might need to

clear:left
the container that follows your list of products as you may find that it joins them! (Ok, that wouldn't happen to a table! ;)

Marshall

11:55 pm on Jul 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



penders,

That works really nice.

Marshall

penders

12:16 am on Jul 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That works really nice.

Along the same lines as your suggestion above :) - it's just that I think it's important to keep the product name and the product image together - nice and cosy!

Has that quashed the table rebellion?

Marshall

12:27 am on Jul 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Has that quashed the table rebellion?

Doubt it!

Marshall

On a side note which has nothing to do with this post, do you know how many time I accidently typed &quote; instead of &quot; in my XML's. Brett, can't you change that? ;)

penders

12:43 am on Jul 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



...do you know how many time I accidently typed &quote; instead of &quot; in my XML's.

47?

Marshall

12:46 am on Jul 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



47?

Close! &quot; appears 48 times in the file I am currently working on. Spooky that you were so close.

Marshall

Are we way off topic or what!?

amdowney

2:18 pm on Jul 13, 2007 (gmt 0)

10+ Year Member



Thanks for replies guys!

amdowney

12:31 pm on Jul 19, 2007 (gmt 0)

10+ Year Member



I went with the method penders suggested, howerver all sorts of issues arise with older versions of IE. Take a look at <snip> in an older browser now and you will see, although I will be correcting shortly...

[edited by: SuzyUK at 7:37 am (utc) on July 25, 2007]

amdowney

2:00 pm on Jul 19, 2007 (gmt 0)

10+ Year Member



I am reverting to tables for now with this and the header.

Your opinions would be appreciated

[edited by: jatar_k at 2:35 pm (utc) on July 19, 2007]
[edit reason] no urls thanks [/edit]

penders

8:46 pm on Jul 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I went with the method penders suggested, howerver all sorts of issues arise with older versions of IE.

By itself, the code I posted above works fine in both IE5 and 6 with a Transitional DOCTYPE (which you seem to be using). However, I've not tried IE5.5 (?)

You could try adding

display:inline
to the floated
li
rule to may be get around any IE float bug?

.products li { 
display:inline;
:
: