Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DIV in <td> float right

Tags:

html

css

asp.net

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...

like image 331
Swag Avatar asked Jul 30 '13 19:07

Swag


People also ask

How do you float a div to the right?

Use CSS property to set the height and width of div and use display property to place div in side-by-side format. float:left; This property is used for those elements(div) that will float on left side. float:right; This property is used for those elements(div) that will float on right side.

What does float right do?

The float CSS property places an element on the left or right side of its container, allowing text and inline elements to wrap around it. The element is removed from the normal flow of the page, though still remaining a part of the flow (in contrast to absolute positioning).

What is the difference between float right and text align right?

Float allows other HTML elements to flow around the floating element. Align simply shifts an element to the left or right. Align - You use align to align text and other items rather it be left, right, centered, or justified. Align DOES NOT remove the item from the document flow.


1 Answers

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; }
like image 177
Tim Wasson Avatar answered Sep 29 '22 13:09

Tim Wasson