css - HTML Div Width with Overflow: Auto? -
i'm creating div
following:
edit: here's example:
<html> <body> <table> <tr> <td> <div style="position: relative; overflow: auto; max-height: 15em;"> <label><input type="checkbox"/>hello! hello!</label><br/> <label><input type="checkbox"/>hello! hello!</label><br/> <label><input type="checkbox"/>hello! hello!</label><br/> <label><input type="checkbox"/>hello! hello!</label><br/> <label><input type="checkbox"/>hello! hello!</label><br/> <label><input type="checkbox"/>hello! hello!</label><br/> <label><input type="checkbox"/>hello! hello!</label><br/> <label><input type="checkbox"/>hello! hello!</label><br/> <label><input type="checkbox"/>hello! hello!</label><br/> <label><input type="checkbox"/>hello! hello!</label><br/> <label><input type="checkbox"/>hello! hello!</label><br/> <label><input type="checkbox"/>hello! hello!</label><br/> <label><input type="checkbox"/>hello! hello!</label><br/> <label><input type="checkbox"/>hello! hello!</label><br/> <label><input type="checkbox"/>hello! hello!</label><br/> <label><input type="checkbox"/>hello! hello!</label><br/> <label><input type="checkbox"/>hello! hello!</label><br/> <label><input type="checkbox"/>hello! hello!</label><br/> </div> </td> </tr> </table> </body> </html>
the text of every label unnecessarily wraps next line.
how fix this?
attempt 1
add div
,
white-space: nowrap;
the problem vertical scrollbar appears impedes on content introducing small unnecessary horizontal scrollbar.
attempt 2
add div
,
white-space: nowrap; padding-right: 1.5em; // increase appropriate
the problem here you're guessing size of vertical scrollbar remove horizontal one.
attempt 3
add div
,
white-space: nowrap; overflow-x: hidden; overflow-y: scroll;
now, horizontal scrollbar removed, , size of vertical 1 not being guessed, but visible.
attempt 4
the problem seems boil down needing reserve space scrollbar, overflow-y: scroll;
without being visible. first solution came mind add div
alongside first has overflow-y: scroll;
set , width: 100%;
. problem regular div
scrollbar included in width. after trial , error though, seems if use float
isn't. using float
can force width of container larger scrollbars width, , setting width: 100%;
on original div, take space too. hide float setting it's height 0
.
n.b. i'm not entirely sure why works myself, , i've tested on firefox5 seems work. hope it's helpful you. so,
add,
<div class="hack"></div>
below you're original div
. then,
.content { float: left; width: 100%; overflow-y: auto; max-height: 15em; } .hack { float: left; width: 100%; overflow-y: scroll; height: 0; }
an edit of jsfiddle including fix here.
Comments
Post a Comment