Forum Moderators: not2easy
Is there a CSS equivalent to this? I'd like to align some text to the left and other text to the right on the same line, and avoid using tables if I can. I've been unable to duplicate this using <div>, <span> and text-align.
<table width="100%">
<tr>
<td width="20%" align="left">this is on the left</td>
<td width="*" align="center">this is in the middle</td>
<td width="20%" align="right">this is on the right</td>
</tr>
</table>
[pre]
.left {
width: 33%;
float: left;
}
.right {
width: 33%;
float: right;
text-align: right;
}<p class="left">This is on the left</p>
<p class="right">And this is on the right</p>
<p class="right">And this is the middle</p>
[/pre]
You could change those percentages but you'd need to add margins and or padding to compensate....
Nick
.leftalign {width: 20%;
text-align: left;}
.centered{text-align: center;
width: 60%;}
.rightalign{width: 20%;
text-align: right;}
<p>
<span class="leftalign">left-aligned text goes here</span><span class="centered">centred text goes here</span><span class="rightalign">right-aligned text goes here</span></p>
I'm sure there must be a problem with this ...
[pre]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "xhtml11.dtd">
<?xml version="1.0" encoding="iso-8859-1"?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<style type="text/css">
.left {
width: 33%;
float: left;
}
.right {
width: 33%;
float: right;
text-align: right;
}
</style>
<title>Menu Hover Boxes</title>
</head>
<body><p class="left">This is on the left</p>
<p class="right">And this is on the right</p>
<p class="right" style="text-align: center;">And this is the middle</p>
</body>
</html>
[/pre]
Nick
Using a variant of the solution listed here causes problems in smaller windows, as 20% of the screen is now less than the width of the text and it wraps to the next line, even though there is white space free. I've tried using different values but it seems to mess up the design even more. Removing the width specification seems to work fine in IE 6, but I still have wrapping problems in Opera 6.
I'm searching for a more elegant solution but so far that has been fruitless...
Anyhow, here is my code as it stands right now:
.leftalign{
position: relative;
padding-left: .5em;
float: left;
color: #9090B0;
font-weight: bold;
}
.rightalign{
position: relative;
padding-right: .5em;
float: right;
text-align: right;
color: #707090;
}
<div class="leftalign">Left part</div>
<div class="rightalign">Right part</div><br>
I'm using <div> tags as <p> stands for nothing but pain, pain and more pain in Opera.