DIV in float right

I got a table with a couple <td>:

<table>
 <tr>
  <td>First</td>
  <td>Second</td>
  <td style="padding:20px;">
      <div>
        Third
      </div>
  </td>
 </tr>
</table>

What I want to do is to place the “Third” <td> (with the div) to the right side of the table and the “First” and “Second” <td> should stay left.

Style with float:right; didn’t work for me…

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You need to make your table’s width 100%, then control the widths of your first 2 columns, and finally right-align your third column.

http://jsfiddle.net/25Mqa/1/

<table>
 <tr>
  <td class="first">First</td>
  <td class="second">Second</td>
  <td class="third">Third</td>
 </tr>
</table>

CSS:

table { width:100%; }
.first, .second { width:50px; }
.third { text-align:right; }

Method 2

The problem is that the width of a <table> is determined by its content, by default. If you want the <table> to span 100% width (of its containing block) like block-level elements do, you can either add table-layout: fixed; and then specify your width – or just give it a width, depending on what you’re after, e.g.

table {
   width: 100%;
}

http://jsfiddle.net/QEaAd/2/

Method 3

try add style="text-align:right;"

<table>
 <tr>
  <td>First</td>
  <td>Second</td>
  <td style="padding:20px; text-align:right;">
      <div>
        Third
      </div>
  </td>
 </tr>
</table>

Only if you have 2 divs one near other:

<div id="fr">div1</div>
<div id="fr">div2</div>

you can float them right:

<style>
#fr{float:right;}
</style>

Method 4

<table style="width: 100%;">
 <tr>
  <td>First</td>
  <td>Second</td>
  <td style="padding:20px; display: block; float: right;">
      <div>
        Third
      </div>
  </td>
 </tr>
</table>

http://jsfiddle.net/pbesD/

I believe this does what you want, however from what I understand, floating table elements will cause problems in versions of Internet Explorer <8

Method 5

I dont know what you are trying to do with tables and divs? But I normally use this for emailers.

I use the align attribute for td’s. This helps a lot in making sure your layout looks the way you want. And it works in all browsers 🙂

FIDDLE

HTML:

<table width="100%">
 <tr>
  <td>First</td>
  <td>Second</td>
  <td style="padding:20px;" align="right">
      <div>
        Third
      </div>
  </td>
 </tr>
</table>


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x