I want to create a sidebar sitting to the left of a text container, but I'm very unsure if my method is dependable across browsers!
Basically, I rely on a fixed positioned sidebar but avoiding to set left
to anything so that it is contained within its parent.
Is this a default behaviour or something different browsers handle in their own little funny ways?
Example fiddle: https://jsfiddle.net/7enadwus/
Example code:
<div class="container">
<p>Some text</p>
</div>
<div class="float">
<div class="sidebar">
<p>Sidebar</p>
</div>
</div>
.container {
width: 100%;
height: 600px;
background-color: red;
max-width: 400px;
margin-left: auto;
margin-right: auto;
}
.float {
position: relative;
height: 10px;
width: 100%;
max-width: 800px;
margin-left: auto;
margin-right: auto;
background-color: blue;
}
.sidebar {
position: fixed;
top: 0;
}