I'm having an incredibly difficult time achieving the following effect:
==========================================================
= Variable Width = <input style="width: 100%" /> =
==========================================================
I am using the following HTML:
<dl>
<dt>
<label>Variable Width</label>
</dt>
<dd>
<input style="width: 100%" />
</dd>
</dl>
Please note that I've trimmed down the HTML for readability.
Can anyone suggest what CSS I should use to achieve this effect? I would prefer to not have to use display: table
because I am looking for cross-browser compatibility that reaches IE7.
To merge table columns in HTML use the colspan attribute in <td> tag. With this, merge cells with each other. For example, if your table is having 4 rows and 4 columns, then with colspan attribute, you can easily merge 2 or even 3 of the table cells.
The CSS to make all the columns equal in width is as follows. The table-layout: fixed; rule specifies that the table is to take its dimensions from the <table> element's width and the width of the first row of cells (or the <col> elements, if you have them).
Using float and margin The left div is styled with width:50% and float:left – this creates the green colored div that horizontally covers half of the screen. The right div is then set to margin-left:50% – this immediately places it to the right of the left div.
The most common way to place two divs side by side is by using inline-block css property. The inline-block property on the parent placed the two divs side by side and as this is inline-block the text-align feature worked here just like an inline element does.
This is "incredibly difficult" to do without <table>
or display: table
.. until you know how!
See: http://jsfiddle.net/thirtydot/aLgwt/
This works in IE7 and greater + all modern browsers.
dt {
float: left
}
dd {
overflow: hidden;
padding: 0 4px 0 9px
}
dd input {
width: 100%
}
An explanation of why it works is here.
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