HighDots Forums  

Aligning images and text with CSS instead of tables

Cascading Style Sheets Layout/presentation on the WWW (comp.infosystems.www.authoring.stylesheets)


Discuss Aligning images and text with CSS instead of tables in the Cascading Style Sheets forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Benjamin Esham
 
Posts: n/a

Default Aligning images and text with CSS instead of tables - 07-06-2009 , 10:47 AM






Hello all,

I am trying to replace some <table>s on one of my websites with clean CSS
markup. I'm having trouble getting images and text to align in exactly the
way I want. The old markup looked like

<table><tr>
<td><img src="..." /></td>
<td>some text here</td>
</tr></table>

with the effect that the text was placed to the right of the image; the
vertical center of the text was aligned with the vertical center of the
image. This is what I'd like to reproduce with CSS. I started by trying

<p>
<img src="..." style="vertical-align: middle" />
<span style="vertical-align: middle">some text here</span>
</p>

This works great for small amounts of text. However, if the text wraps, the
second line begins below the image, whereas I'd like *all* of the text to be
positioned to the right of the image (and with the vertical centers still
aligned). Can anyone offer me some advice about how to set this up?

Many thanks!

--
Benjamin D. Esham | bdesham (AT) gmail (DOT) com | bdesham128 (AIM)
"Lasciate ogne speranza, voi ch'intrate." — Hell (via Dante)

Reply With Quote
  #2  
Old   
BootNic
 
Posts: n/a

Default Re: Aligning images and text with CSS instead of tables - 07-06-2009 , 01:18 PM






On Mon, 06 Jul 2009 14:47:55 GMT
Benjamin Esham <bdesham (AT) gmail (DOT) com> wrote:

Quote:
Hello all,

I am trying to replace some <table>s on one of my websites with clean
CSS markup. I'm having trouble getting images and text to align in
exactly the way I want. The old markup looked like

table><tr
td><img src="..." /></td
td>some text here</td
/tr></table

with the effect that the text was placed to the right of the
image; the vertical center of the text was aligned with the
vertical center of the image. This is what I'd like to reproduce
with CSS. I started by trying

p
img src="..." style="vertical-align: middle" /
span style="vertical-align: middle">some text here</span
/p

This works great for small amounts of text. However, if the text
wraps, the second line begins below the image, whereas I'd like
*all* of the text to be positioned to the right of the image (and
with the vertical centers still aligned). Can anyone offer me
some advice about how to set this up?
..img {
overflow: hidden;
color:#000;
background-coloralegreen;
margin: 0 0 0.5em 0;
zoom:1;
}
..img img {
float:left;
width:64px; /* width of image */
height:64px; /* height of image */
margin:5px;
}
..img div {
margin-left:74px; /* width of image + left & right margin */
padding-left: 0.3em;
color:#000;
background-color:lightyellow;
min-height:74px; /* height of image + top & bottom margin; */
}

<div class="img">
<img alt="example image" src="/example.png" width="64"
height="64">
<div>
<p>
Lorem ipsum …
</p>
<p>
Etiam dictum …
</p>
</div>
</div>

Float image example:
http://bootnic.bounceme.net/FloatImage.php



--
BootNic Mon Jul 6, 2009 01:18 pm
It is better to die on your feet than to live on your knees!
*Emiliano Zapata*

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (GNU/Linux)

iEYEARECAAYFAkpSMdkACgkQmo2774GZ7qlAjwCfUlOYpgJc58 YGsW4E50d8b6vr
XzAAnAs9MXe58eqc5oGb3QrVnQWQEAJ/
=Q/nX
-----END PGP SIGNATURE-----

Reply With Quote
  #3  
Old   
Beauregard T. Shagnasty
 
Posts: n/a

Default Re: Aligning images and text with CSS instead of tables - 07-06-2009 , 03:18 PM



Benjamin Esham wrote:

Quote:
I am trying to replace some <table>s on one of my websites with clean
CSS markup. I'm having trouble getting images and text to align in
exactly the way I want. The old markup looked like ...
...
This works great for small amounts of text. However, if the text
wraps, the second line begins below the image, whereas I'd like *all*
of the text to be positioned to the right of the image (and with the
vertical centers still aligned). Can anyone offer me some advice
about how to set this up?
If you don't mind a comment, rather than a solution, I'll venture that
right-side text aligned to the middle of a left-side image is unfriendly
to eye-flow - especially if the images are any significant amount of
height greater than the text.

I see what you are after on a lot of very amateur web sites.


+----------------------+
Quote:
|
|
(big |
img) | We stayed at this beach house
|
|
|
+----------------------+

--
-bts
-Friends don't let friends drive Windows

Reply With Quote
  #4  
Old   
dorayme
 
Posts: n/a

Default Re: Aligning images and text with CSS instead of tables - 07-06-2009 , 06:45 PM



In article <v8o4m.50412$IU6.31814 (AT) newsfe05 (DOT) iad>,
Benjamin Esham <bdesham (AT) gmail (DOT) com> wrote:

Quote:
Hello all,

I am trying to replace some <table>s on one of my websites with clean CSS
markup. I'm having trouble getting images and text to align in exactly the
way I want. The old markup looked like

table><tr
td><img src="..." /></td
td>some text here</td
/tr></table

with the effect that the text was placed to the right of the image; the
vertical center of the text was aligned with the vertical center of the
image. This is what I'd like to reproduce with CSS. I started by trying

p
<img src="..." style="vertical-align: middle" /
<span style="vertical-align: middle">some text here</span
/p

This works great for small amounts of text. However, if the text wraps, the
second line begins below the image, whereas I'd like *all* of the text to be
positioned to the right of the image (and with the vertical centers still
aligned). Can anyone offer me some advice about how to set this up?

Yes, I see what you want. Clean CSS. Text middle with image middle. No
HTML tables. Sometimes you can have any two of a list of three. (Some
consultants like telling their clients that they can have cheap, good,
quick, pick any two! <g>)

1. The table markup certainly gets clean CSS because there is hardly any
need for much. Plus it is particularly apt for what you want in look and
behaviour, and plus it is semantically kosher if anything is. Why would
you resist it? I trust not for any silly reason like you should never
really use tables unless it relates prices to products or for something
very scientific looking!

2.Using CSS to make various elements behave like tables and cells.
Downside is browser support. Not bad on Safari, Firefox, iCab, Opera:

<http://dorayme.netweaver.com.au/byTableCSS.html>

3. Your non-table markup above with a little CSS would solve but it
would be a bit annoying: p {width: 1000000px}. <g>

--
dorayme

Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.