Problems with text-alignments.

Hi,

very often I need to put two short pieces of text in one line such
that the first piece is aligned to the left of the line and the second
one to the right. The way I do it is as following:

<table width='100%' border='0'><tr><td>
<div align='left'> piece 1 </div>
</td><td>
<div align='right'> piece 2 </div>
</td></tr></table>

But I think it is not an elegant way to solve the problem. Do you know
a better one? (Pleas do not tell me to go to work in MacDonald's :) )
showandbeshown [ Di, 08 April 2008 03:16 ] [ ID #1938387 ]

Re: Problems with text-alignments.

"Fro" <showandbeshown [at] gmail.com> wrote in message
news:829a2002-022a-4056-81b0-cd7a50e7ddcb [at] k37g2000hsf.google groups.com...
> Hi,
>
> very often I need to put two short pieces of text in one line such
> that the first piece is aligned to the left of the line and the second
> one to the right. The way I do it is as following:
>
> <table width='100%' border='0'><tr><td>
> <div align='left'> piece 1 </div>
> </td><td>
> <div align='right'> piece 2 </div>
> </td></tr></table>
>
> But I think it is not an elegant way to solve the problem. Do you know
> a better one? (Pleas do not tell me to go to work in MacDonald's :) )

Try this below (styles declared inside HTML, but easy enough to incorporate
into your external stylesheet).

The idea is that the text 'floats' to either left or right. Note that a
0.5em spacing is applied to left or right to ensure at least a 1em space
between the elements.

Beware of the 'clearright' css class... it may misbehave if you have other
right-floating elements in your page.

Not really sure if it's more 'elegant', but worth consideration?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Tester</title>
<style type="text/css">
<!--
..lefttext {
text-align: left;
float: left;
margin-right: 0.5em;
}
..righttext {
float: right;
margin-left: 0.5em;
text-align: right;
}
..clearright {
clear: right;
}
-->
</style>
</head>
<body>
<div class="lefttext">leftmost text area</div><div
class="righttext">rightmost text area</div>
<p class="clearright">next paragraph next paragraph next paragraph next
paragraph next paragraph next paragraph next paragraph next paragraph next
paragraph next paragraph next paragraph next paragraph next paragraph next
paragraph next paragraph next paragraph next paragraph next paragraph next
paragraph next paragraph next paragraph next paragraph next paragraph next
paragraph next paragraph next paragraph next paragraph next paragraph next
paragraph next paragraph next paragraph next paragraph next paragraph next
paragraph next paragraph next paragraph next paragraph next </p>
</body>
</html>
23s [ Di, 08 April 2008 03:49 ] [ ID #1938391 ]

Re: Problems with text-alignments.

On 07 Apr 2008, Fro <showandbeshown [at] gmail.com> wrote:

> Hi,
>
> very often I need to put two short pieces of text in one line such
> that the first piece is aligned to the left of the line and the second
> one to the right. The way I do it is as following:
>
> <table width='100%' border='0'><tr><td>
> <div align='left'> piece 1 </div>
> </td><td>
> <div align='right'> piece 2 </div>
> </td></tr></table>
>
> But I think it is not an elegant way to solve the problem. Do you know
> a better one? (Pleas do not tell me to go to work in MacDonald's :) )

Burger Koenig, der hamburger fuhrer, uber alles!

As asdf implied, read-up on floats (but don't let them rain on your
parade...)

--
Neredbojias
http://www.neredbojias.com/
Great sights and sounds
Neredbojias [ Di, 08 April 2008 06:44 ] [ ID #1938401 ]

Re: Problems with text-alignments.

Fro wrote:
> Hi,
>
> very often I need to put two short pieces of text in one line such
> that the first piece is aligned to the left of the line and the second
> one to the right. The way I do it is as following:
>
> <table width='100%' border='0'><tr><td>
> <div align='left'> piece 1 </div>
> </td><td>
> <div align='right'> piece 2 </div>
> </td></tr></table>
>
> But I think it is not an elegant way to solve the problem. Do you know
> a better one? (Pleas do not tell me to go to work in MacDonald's :) )

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta http-equiv="content-language" content="en-us">

<title>bookends</title>

<style type="text/css">
div.bookends { text-align: right; }
div.bookends span { float: left; }
</style>
</head>
<body>
<div class="bookends"><span>piece 1</span>piece 2</div>
</body>
</html>


--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
lws4art [ Di, 08 April 2008 07:10 ] [ ID #1938403 ]
Miscellaneous » alt.html » Problems with text-alignments.

Vorheriges Thema: Daylight saving in NSW
Nächstes Thema: More Form Mail Replies - OT