tags:

views:

25

answers:

1

I am aware that you can center a block item by setting the left and right margin to auto.

However, is it possible to align it to the right edge? And how would this be done?

Edit: without using float: right (because it doesn't seem to work, at least not with <ul>'s)

Edit again: Here is a snippet of the code:

<td style='vertical-align: top; text-align: center;'>
  <b>Choices:</b><br><br>
  <ul id='orderchoices' style='margin-left: auto; margin-right: auto;'>
    ...
  </ul>
</td>

Here is the style for #orderchoices

#orderchoices li {
  border: 1px solid #666;
  background: #333 url(images/dark_gloss.png) repeat-x;
  color: #eee;
  margin: 3px;
  padding: 5px;
  cursor: pointer;
  width: 160px;
  font-style: italic;
}

I want the ul right-aligned in the td

A: 
<div class="outer">
    <div class="inner">I'm the inner element!</div>
</div>
<style type="text/css">
    .outer { position:relative; }
    .inner { position:absolute; right:0px; }
</style>

If your inner element is positioned absolutely within a container that is positioned relatively, you can use top, right, bottom and left to indicate the inner element's distance from the edges of the parent container.

Make sense?

inkedmn
Sure and thanks for pointing this out. But what an ugly way to have to do it! I hope CSS4 has a better solution for this.
George Edison
Hmmm. After giving it a try, it seems like the `position:absolute;` is causing the element to run off the edge of the page. (At the bottom)
George Edison
I use this technique *regularly* - please update your question to include any relevant markup or CSS that's already being applied because something else is afoot, here :)
inkedmn
@inkedmn: Posted above.
George Edison