Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > how to evenly space a row of images using CSS

Reply
Thread Tools

how to evenly space a row of images using CSS

 
 
Greg N.
Guest
Posts: n/a
 
      05-16-2005
I'm new at CSS, so bear with me if this is a trivial or impossible thing
to do.

I have a few images that I want to place side by side, evenly spaced
across the page, such that the right image aligns with the right edge of
the browser window.


<----------- browser window width ---------------->
image1 image2 image3 image4


That means, as the window is resized, the spacing should adapt accordingly:


<--- browser window width --->
image1 image2 image3 image4


It's fairly easy to implement this with tables, but how about a pure
CSS implementation?

Thanks - Greg
 
Reply With Quote
 
 
 
 
Spartanicus
Guest
Posts: n/a
 
      05-16-2005
"Greg N." <> wrote:

>I have a few images that I want to place side by side, evenly spaced
>across the page, such that the right image aligns with the right edge of
>the browser window.
>
><----------- browser window width ---------------->
>image1 image2 image3 image4
>
>It's fairly easy to implement this with tables, but how about a pure
>CSS implementation?


Not possible, with or without tables. The only way to achieve this is by
using text-align:justify, but that only works when the content wraps.

--
Spartanicus
 
Reply With Quote
 
 
 
 
Greg N.
Guest
Posts: n/a
 
      05-16-2005
Spartanicus wrote:

> Not possible, with or without tables. The only way to achieve this is by
> using text-align:justify, but that only works when the content wraps.


Sure possible with tables. Just align the image in the leftmost cell
left, the image in the rightmost cell right, center the other images in
their cells and give the cells appropriate widths in percent. Works like
a charm.
 
Reply With Quote
 
Greg N.
Guest
Posts: n/a
 
      05-16-2005
Greg N. wrote:
> Spartanicus wrote:
>
>> Not possible, with or without tables. The only way to achieve this is by
>> using text-align:justify, but that only works when the content wraps.

>
>
> Sure possible with tables. Just align the image in the leftmost cell
> left, the image in the rightmost cell right, center the other images in
> their cells and give the cells appropriate widths in percent. Works like
> a charm.


Example:

<table width=100%>
<tr>
<td width=17% align=left><img
src=http://www.icons.com/images/home2/token_GvB.gif>
<td width=33% align=center><img
src=http://www.icons.com/images/home2/token_heggem.gif>
<td width=33% align=center><img
src=http://www.icons.com/images/home2/token_grimandi.gif>
<td width=17% align=right><img
src=http://www.icons.com/images/home2/token_job.gif>
</table>
 
Reply With Quote
 
Spartanicus
Guest
Posts: n/a
 
      05-17-2005
"Greg N." <> wrote:

>> Not possible, with or without tables. The only way to achieve this is by
>> using text-align:justify, but that only works when the content wraps.

>
>Sure possible with tables. Just align the image in the leftmost cell
>left, the image in the rightmost cell right, center the other images in
>their cells and give the cells appropriate widths in percent. Works like
>a charm.


Right you are, there is an alternative without using a html table, but
it's a bit messy: http://homepage.ntlworld.com/spartanicus/justify.htm

It's buggy in IE due to what appears to be rounding errors in adding the
widths of the individual elements, maybe there's a hack to solve that.

Another possible method could be to float four 25% width containers.

Note that these methods do not allow the images to wrap if the window
width isn't wide enough, thus you are better off choosing a different
layout.

--
Spartanicus
 
Reply With Quote
 
dorayme
Guest
Posts: n/a
 
      05-17-2005
> From: "Greg N." <>

> Greg N. wrote:
>> Spartanicus wrote:
>>
>>> Not possible, with or without tables. The only way to achieve this is by
>>> using text-align:justify, but that only works when the content wraps.

>>
>>
>> Sure possible with tables. Just align the image in the leftmost cell
>> left, the image in the rightmost cell right, center the other images in
>> their cells and give the cells appropriate widths in percent. Works like
>> a charm.

>
> Example:
>
> <table width=100%>
> <tr>
> <td width=17% align=left><img
> src=*>
> <td width=33% align=center><img
> src=*>
> <td width=33% align=center><img
> src=*>
> <td width=17% align=right><img
> src=*>
> </table>


This *nearly* satisfies you wanting "to place side by side, evenly spaced
across the page, such that the right image aligns with the right edge of
the browser window" but it is not strictly even between each pic. In a 900px
wide table the lengths would go 40,110,130,40,130,130,40,130,110,40 where 40
are your pics and the rest the distances from edges of same.

("evenness" might be had or simulated by changing the balance of percentages
of the cells.)

I have so often ended up using tables for similar requirements. But am
interested in your question.

dorayme

 
Reply With Quote
 
Greg N.
Guest
Posts: n/a
 
      05-17-2005
Spartanicus wrote:

> http://homepage.ntlworld.com/spartanicus/justify.htm


I'd say that's exactly what I was after. Thanks.
 
Reply With Quote
 
Greg N.
Guest
Posts: n/a
 
      05-17-2005
Greg N. wrote:

>> http://homepage.ntlworld.com/spartanicus/justify.htm

>
> I'd say that's exactly what I was after. Thanks.


Hmm... this is CSS2 stuff, isn't it?
 
Reply With Quote
 
Spartanicus
Guest
Posts: n/a
 
      05-17-2005
"Greg N." <> wrote:

>>> http://homepage.ntlworld.com/spartanicus/justify.htm

>>
>> I'd say that's exactly what I was after. Thanks.

>
>Hmm... this is CSS2 stuff, isn't it?


A mix of css 2.0 (table values) and 2.1 (inline-block value).

The table values are used by proper browsers (Opera, Gecko and KHTML
browsers), IE5.5+ uses the inline-block value.

--
Spartanicus
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
do replacement evenly oyster Python 3 06-02-2009 02:44 PM
How to space out the elements evenly in an ASP.NET menu PromisedOyster ASP .Net 0 11-23-2006 11:41 AM
easiest way to split a list into evenly divisble smaller lists, and assign them to variables? flamesrock Python 3 06-07-2005 02:17 AM
Why Python style guide (PEP-8) says 4 space indents instead of 8 space??? 8 space indents ever ok?? Christian Seberino Python 21 10-27-2003 04:20 PM
Stack space, global space, heap space Shuo Xiang C Programming 10 07-11-2003 07:30 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57