Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

position:fixed no scroll bars appearing

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.

like image 745
John Colvin Avatar asked Aug 05 '11 00:08

John Colvin


People also ask

Why is my scroll bar not showing?

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.

Why is position fixed not working?

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.


1 Answers

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.

like image 98
bitmask Avatar answered Oct 05 '22 08:10

bitmask