Jump to content

Recommended Posts

Posted

Ok, so let's say you have a nice big DIV and you want one thing to be aligned on the left side and the other to be aligned on the right side both items being on the same line.

 

How would you do that with CSS and not tables?

 

In a table, you'd obviously do this:

><table>
<tr>
     <td align="left" valign="top">this is aligned left</td>
     <td align="right" valign="top">this is aligned right</td>
</tr>
</table>

So ... how would I do this in one DIV without doing like 5 divs or something Yuck! I remember seeing this somewhere's but can't remember where.

 

This is useful, for example, when you have a header div with a logo on the left side and some text links on the right side aligned to the right.

 

later,

!!blue

Posted

I'm not exactly a CSS expert, but I do not believe you can align two things in a single div. I believe it will require two divs (but you can nest divs).

Posted

thanks guys! I guess I'll have some "divitis" on my page (from Zeldman's book desiging with web standards where everything on a page is in its own DIV :blink: ). But, I think I can do it with one div and two span classes.

 

*goes off to work it out*

 

thanks again,

!!blue

Posted

blue,

 

This method uses two divs, but it works very well. You might give it a try if you haven't yet done it.

 

The CSS code is:

>#left {
 float: left;
 text-align: left;
 color: #fff;
 width: 49%;}

#right {
 float: right;
 text-align: right;
 color: #fff;
 width: 49%;}

#rowcontent{
 width: 300px;
 background-color: #CCC;
 border: 1px solid #000;
 padding: 0px;
 margin: 0px auto;}

.defloat {
 clear: both;}

 

The HTML code is:

><div id="rowcontent">
 <div id="left">Left-Aligned Text</div>
 <div id="right">Right-Aligned Text</div>
 <div class="defloat"> </div> <!-- use this to bring all of your floated elements back down to the page -->
</div>

 

Yes, it adds a few divs to your markup, but it's really quite similar to the original table example you gave. I've successfully used this method and was pleased with the results.

Posted

Dave,

 

Thanks for pointing out where this method came from (and for providing the URL). That URL is definitely where I learned the technique, but I couldn't remember where it had come from. But I most certainly remember the giraffe, so that's got to be it!

 

Thanks again, and now I've actually bookmarked the RealWorldStyle.com web site!

 

Thumbs Up

Posted

I *knew* I had seen it somewhere before but didn't bookmark it! :lol:

 

Anyhow, I used one div and two spans but it was basically the same idea as the code example! :D I'll go back and add in the {clear: both;} bit.

 

thanks!

!!blue

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...