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.
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.
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.
html should be table and width: 100% . span should be margin: auto; .
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.
Use the "colspan" property of td. Ex:
<td colspan=75%> info </td>
Solved adding the width:100%
to the table.
http://jsfiddle.net/HRT5E/1/
table { width:100%; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With