The container may be any block level element; a heading, paragraph, list and/or list item, form, blockquote, etc., even line breaks and horizontal rules. Add to this, most inline level elements can be made into block level with CSS.
For tight fit, you may still use variable size images. Just truncate the left side (or right as applies) of images wider than what the layout permits.
These would be my considerations to build on the version above:
* Set width percentage for all browsers.
* Set min-width, max-width to get a predictable layout in the standards compliant browsers.
* Set overflow:hidden; since height is not set, only leftbound edge will be clipped.
* Set text align right.
* Set image to display inline so it respects the text alignment.
So the above becomes,
Code:
div.container{
width:25%;
min-width:200px;
max-width:300px;
overflow:hidden;
text-align:right;
color:inherit;
background:rgb(204,237,237) url(right_border_fill_image.gif) repeat-y 100% 0%;
}
div.container img{
display:inline;
margin:10px 15px 10px 0px;
}
Bear in mind that you need only a single container in this example, with no limit on how many images you stack into it, making it structurally very simple with really portable code.
Now it gets better... If you wanted a border all around, and to be able to tight-fit your image (left, right or center aligned) you could make the image a CSS background. This is a handy way to get rid of image tags in a layout. Consider, for example,
Code:
div.container span{
display:block;
width:100%;
height:150px; /* set to image height */
margin:0px;
border:10px solid rgb(204,237,237);
border-right-width:0px; /* or border-right:none */
background:transparent url(visual_value_only.jpg) no-repeat 90% 0%;
}
Further, with a couple of tweaks we can stretch this into the realm of multiple objects by giving the span a class which is assigned a specific image and corresponding height:
Code:
div.container span{
display:block;
width:100%;
margin:0px;
border:10px solid rgb(204,237,237);
border-right-width:0px;
}
div.container span.visual_a{
height:150px;
background:transparent url(visual_a.jpg) no-repeat 90% 0%;
}
div.container span.visual_b{
height:120px;
background:transparent url(visual_b.jpg) no-repeat 90% 0%;
}
Now the image can be any size, and will only be clipped on the left side, without affecting the border. The height must be specified. Position is set to 90% to allow 20px right margin for border background at min-width, 30px at max-width. Your border image would need to be minimum 30px to meet the full requirements of the layout being considered.
To center horizontally, set the first percentage to 50%. This will clip both right and left.
The same applies when the height is fixed. Set the second percentage accordingly, depending on what portion of the image you are willing to sacrifice in the truncation.
Most importantly, using background images should only be considered for the 'non-descriptive, visual value' images. If the image is central to the content, img tags should be used. The alt text (and title text) is available to spiders and screen readers.
On the other hand, most newer browsers will recognize a title attribute in most element, so a descriptive title can still be used in the span tags used above. Then there is always the text that you can insert in the empty span, and style for fit and finish.
There is still no way to physically associate the text to the actual image in the background, though, no matter how much the title or span text describes it, so go with care. Layout and visual value only is the best rule.
Truly powerful stuff in creative hands... would you agree?
Cheers, Roy