Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a td fill table width

Tags:

I have a table that has a fixed height of 50px and 100% width.

Inside that table I have two divs, on the same line, like this:

<table>   <tr>     <td>       <div id="1"></div>     </td>     <td>       <div id="2"></div>     </td>   </tr> </table> 

The first div has float:left, and the second has float:right.

So the table is 100% of the page. I want div2 to wrap it's contents, and div1 to fill the remaining space so that div2 is aligned to the right like this:

+--------------------------------------------------------------+ | [ DIV 1          (Expands)       ][ DIV 2 AND ITS CONTENTS ] | +--------------------------------------------------------------+ 

and what I currently get when div1 has less contents than a full line:

+--------------------------------------------------------------+ | [ DIV 1 ][ DIV 2 ]                                           | +--------------------------------------------------------------+ 

Without a table I can get it to work floating left and right directly, but then when they "get together", they will wrap under each other instead of next to each other.

EDIT: I've added a new jsfiddle here. This is the working example. Try removing all but one links from the left div, and see the result. The second div should stay at the most-right. I hope I explained myself.

like image 603
Twinone Avatar asked Feb 13 '13 20:02

Twinone


People also ask

How do I set the width of a TD table?

By using CSS, the styling of HTML elements is easy to modify. To fix the width of td tag the nth-child CSS is used to set the property of specific columns(determined by the value of n) in each row of the table.

How do you make a table TD and width the same?

Using table-layout: fixed as a property for table and width: calc(100%/3); for td (assuming there are 3 td 's). With these two properties set, the table cells will be equal in size.

How do you make a full width occupy table?

html should be table and width: 100% . span should be margin: auto; .

How do I set the width and height of a TD table?

To set the cell width and height, use the CSS style. The height and width attribute of the <td> cell isn't supported in HTML5. Use the CSS property width and height to set the width and height of the cell respectively. Just keep in mind, the usage of style attribute overrides any style set globally.


2 Answers

Use the "colspan" property of td. Ex:

    <td colspan=75%> info </td> 
like image 184
tymeJV Avatar answered Oct 17 '22 00:10

tymeJV


Solved adding the width:100% to the table.

http://jsfiddle.net/HRT5E/1/

table {     width:100%; } 
like image 29
Twinone Avatar answered Oct 17 '22 00:10

Twinone