I have a <div>
which is positioned with position:fixed
. When the window is too small horizontally to fit the div, no scroll bars appear, the right hand side of the div is simply cut off.
If I change to position:absolute, the scroll bars appear as normal.
Is there any way of making the browser recognise the size of the div and the need for scrolling whilst still using position:fixed?
Note: there is another div with default position declared before the fixed div.
Show scroll bars in Word and Excel for Windows Click File > Options. On the Advanced tab, scroll to the Display section. Select Show horizontal scroll bar and Show vertical scroll bar, and then click OK.
Position fixed doesn't work with transform CSS property. It happens because transform creates a new coordinate system and your position: fixed element becomes fixed to that transformed element. To fix the problem you can remove transform CSS property from the parent element.
Scrollbars are simply incompatible with a fixed position, logically. If you tell the user-agent to fix something, you should not expect scrollbars as they would move the something. Why don't you use position: absolute
as it appears to work for your example?
Edit:
@Horizontally-scrollable div
: From the top of my head, I'd go about something along the lines of the following css (NOTE: I have not tested this, and it is only supposed to give you a rough idea)
#myContentWrapper {
position: absolute; /* here, fixed or relative may work too*/
left: 0;
right: 0;
top: 0;
bottom: 0;
overflow: scroll; /* also, try auto */
}
#myContentWrapper #myContent {
width: 5000px; /* example */
}
With this, if you nest a div
tag with id="#myContent"
within id="$myContentWrapper"
, I believe it may do what you are looking for.
The difference to your approach is, that the nested element is large, and the parent element is absolute
/fixed
/whatever.
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