If you know the size of your content, you can use the following:
position:fixed; left:800px;
but not:
position:fixed; right:0;
If your content is 800 pixels wide. This means that your calculation works on the left, and the menu will exit the screen if the user window is smaller than this.
Update
It looks like your requirements are as follows:
- You have a content area with a minimum width.
- You need your menu to scroll with the user.
- You need your menu to appear on the right until the menu encroaches on the minimum width of your content.
I would recommend using JavaScript to solve this problem, you can achieve this in pure CSS, but by placing your menu on a fixed layer that spans the entire page. Although the logic here works in modern browsers - due to z-indexing of the contents of the menu-mdash container; I would really like to see what older user agents can do:
pure css version
CSS
.content { position: relative; z-index: 20; min-width: 700px; margin-right: 200px; } .menu-container { position: fixed; z-index: 10; left: 0; right: 0; top: 0; bottom: 0; } .menu-offset { position: relative; min-width: 700px; margin-right: 200px; height: 100%; } .menu-content { position: absolute; width: 200px; height: 100%; left: 100%; background: #ddd; }
Markup
<div class="content"> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis adipiscing magna sed ipsum convallis vel fringilla nibh viverra. Nulla et ligula vel urna scelerisque imperdiet a et lectus. Nunc commodo, nibh id blandit mollis, leo quam eleifend urna, at rhoncus turpis justo sit amet erat. Quisque tempus nunc vitae eros fringilla eget imperdiet neque tincidunt. Donec ac posuere diam. Nam nibh nibh, sollicitudin non blandit ut, auctor in dolor. Nullam lobortis condimentum consequat. </p> <p> Maecenas at orci massa, quis congue mauris. Vivamus varius tincidunt nunc, eget <a href="#canyouclickthis">pellentesque arcu faucibus</a> ac. Suspendisse rhoncus orci eu felis consectetur rutrum. Nullam sed mauris eros. Nunc dignissim, libero dapibus consectetur lobortis, ante urna faucibus dui, vel luctus metus leo id magna. Pellentesque mi ligula, commodo ac pellentesque et, auctor sed neque. Phasellus dapibus tellus faucibus dui vehicula hendrerit. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. </p> </div> <div class="menu-container"> <div class="menu-offset"> <nav class="menu-content">Menu</nav> </div> </div>
With the above, I would expect that older browsers would either render so that you could not interact with anything in the contents of the div - see the link #canyouclickthis - or not support position:fixed anyway:
http://caniuse.com/css-fixed
update 2
And, I just noticed your comment regarding the width of 80% . Modifying the above may work for this, however it is probably best to avoid using percent widths when you have a fixed width menu - especially with the conditions you specify: - and rely on the minimum and maximum widths instead. Either this, or use a menu with a percentage width rather than a fixed one.
Depending on how you set up your markup, the following may work. This approach takes into account the fact that if you do not specify left , top , bottom or right , the layer should remain where it is installed (not 100% true in older browsers). You can specify sizes for the .menu layer for less modern .menu . This solution has an additional advantage: do not close the entier page in a fixed layer :)
.content { position:relative; width:80%; min-width: 800px; float:left; } .menu-container { position:absolute; left:100%; top:0; } .menu-content { position: fixed; width:20%; height:100%; background:#ddd; } <div class="content"> <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis adipiscing magna sed ipsum convallis vel fringilla nibh viverra. Nulla et ligula vel urna scelerisque imperdiet a et lectus. Nunc commodo, nibh id blandit mollis, leo quam eleifend urna, at rhoncus turpis justo sit amet erat. Quisque tempus nunc vitae eros fringilla eget imperdiet neque tincidunt. Donec ac posuere diam. Nam nibh nibh, sollicitudin non blandit ut, auctor in dolor. Nullam lobortis condimentum consequat. </p> <div class="menu-container"> <nav class="menu-content">Menu</nav> </div> </div>
Again, it would be better to test this in Internet Explorer, since I do not have access to this particular user agent.