How can I make the contents of a fixed element scrollable only when it exceeds the height of the viewport?
You probably can't. Here's something that comes close. You won't get content to flow around it if there's space below.
http://jsfiddle.net/ThnLk/1289
.stuck {
position: fixed;
top: 10px;
left: 10px;
bottom: 10px;
width: 180px;
overflow-y: scroll;
}
You can do a percentage height as well:
http://jsfiddle.net/ThnLk/1287/
.stuck {
max-height: 100%;
}
The link below will demonstrate how I accomplished this. Not very hard - just have to use some clever front-end dev!!
<div style="position: fixed; bottom: 0%; top: 0%;">
<div style="overflow-y: scroll; height: 100%;">
Menu HTML goes in here
</div>
</div>
http://jsfiddle.net/RyanBrackett/b44Zn/
Try this on your position:fixed element.
overflow-y: scroll;
max-height: 100%;