I'm having trouble to to style my layout like I want it to. I have a content area #content
(the grey you can see in the example image) with a yellow element inside. This div is position:static;height:100%;
. Now I have a #left-panel
div also, with position:fixed;height:100%;
. The problem is, if the content area has not enough space a horizontally scrollbar appears. This will be overlaped of the fixed div. For me it is all logically, but I don't know how to get around this. My scrollbar of the #content
-element should be visible the whole width of the window. So it would not be a solution for me to just reduce the width of the content if the panel is in view.
The whole css:
#content{
width:100%;
height:100%;
background:grey;
}
#left-panel{
position:fixed;
top:0;
left:0;
width:300px;
height:100%;
overflow-y:auto;
}
Can somebody help me fixing this with pure CSS?
Fiddle: http://jsfiddle.net/a2wn8x5z/1/
First of all, you don't have to add "position: static;" style into your div, because it's static by default. There are two ways to solve your problem:
Add "position: relative;" into #content selector and declare #content after #left-panel in your HTML.
Codepen: http://codepen.io/anon/pen/yoHxl
Or add "position: relative; z-index: 1" (z-index of #content should be higher of #left-panel's) into #content selector.
Codepen: http://codepen.io/anon/pen/HgwDx
Best, Marek
Your wrapper element is
position:fixed;
I think that you are talking about a overlay with a navigation panel on the left. Well, I had a similar situation and found out, that you can't useposition:fixed;
if your parent element is alsoposition:fixed;
. This will overlap the scrollbar of the parent wrapper (the overlay).So you have to use
position:absolute;
instead or use this open source plugin to remove the width/height of the scrollbar from your element:Scrollbar Fixer
perhaps your problem is in this code hereremove the
width:110%;
and it should be good to go.Here's the Updated Fiddle
Edit
I think I misunderstand what's the problem before.
Because on your case, you use
position: fixed;
for#wrapper
and#left-panel
, and both use stlyeleft: 0
, their position will overlap each other in left from the viewport, you basically need to position theleft
of#wrapper
not to be in the same position as#left-panel
, so you need to add this to#wrapper
and remove
here's the Updated Fiddle
to make sure it's what you want, try change the style of the
div
inside#content
towidth:200%;
and addmargin:20px;
Edit Two
the cause for the
scrollbar
to overlap each other is because in the fiddle you useposition: fixed
for the#wrapper
, thus will not create ascrollbar
in thebody
, then you addoverflow:auto
in the#wrapper
, causing thescrollbar
to be created for the#wrapper
and not thebody
, so you need to change theCSS
for#wrapper
to thisI don't include the height because for the
div
, theheight
is based on the child inside it, so you couldn't see the gray background, except you add somepadding
to it.here's the Working Fiddle