Fixed sidebar menu on left and fixed header on top


Pedro

So what I want to do is a fixed sidebar with a fixed menu at the top and scrollable content in the middle.

body,
html {
  height: 100%;
  margin: 0;
}
aside {
  background: #90EE90;
  height: 100%;
  left: 0;
  position: fixed;
  top: 0;
  width: 120px;
}
ul {
  list-style: none;
}
section {
  background: #ADD8E6;
  height: 100%;
  margin-top: 60px;
}
header {
  background: #FF0;
  height: 60px;
  left: 0;
  margin-left: 120px;
  position: fixed;
  text-align: center;
  top: 0;
  width: 100%;
  z-index: 99;
}
.container {
  left: 0;
  margin-left: 120px;
  min-height: 100%;
  position: relative;
  text-align: center;
}
figure {
  margin: 0;
}
img {
  height: 60px;
  width: 100%;
}
<aside>
  <nav>
    <div class="nav-header">
      <figure>
        <img src="http://placehold.it/140x100" alt="" />
      </figure>
    </div>
    <ul>
      <li>Item 1</li>
      <li>Item 2</li>
      <li>Item 3</li>
      <li>Item 4</li>
      <li>Item 5</li>
      <li>Item 6</li>
    </ul>
  </nav>
</aside>
<header>Header Centered</header>
<div class="container">
  <section>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
  </section>
</div>

Here is a fiddle : http://jsfiddle.net/kbb7t7vd/1/

My main problem is that the title is not centered compared to the content section.

I believe this happens because its width is 100% and it's bigger than it should be.

Can I solve this problem without using JS to calculate the width? Maybe I'm just doing the layout the wrong way, and you guys might help me understand it better and how it works.

Thanks in advance.

Kejaye

This problem is indeed related to width: 100%. The text is centered horizontally within a 100% wide header. The header is as wide as the screen, but because the header is also margin-left: 120px120px beyond the right end of the screen.

As you use position: fixed, <header>you can change

header {
   margin-left: 120px;
   left: 0;
   width: 100%;
}

Enter

header {
    left: 120px;
    right: 0;
}

This will center the text horizontally.

body,
html {
  height: 100%;
  margin: 0;
}
aside {
  background: #90EE90;
  height: 100%;
  left: 0;
  position: fixed;
  top: 0;
  width: 120px;
}
ul {
  list-style: none;
}
section {
  background: #ADD8E6;
  height: 100%;
  margin-top: 60px;
}
header {
  background: #FF0;
  height: 60px;
  left: 120px;
  right: 0;
  position: fixed;
  text-align: center;
  top: 0;
  z-index: 99;
}
.container {
  left: 0;
  margin-left: 120px;
  min-height: 100%;
  position: relative;
  text-align: center;
}
figure {
  margin: 0;
}
img {
  height: 60px;
  width: 100%;
}
<aside>
  <nav>
    <div class="nav-header">
      <figure>
        <img src="http://placehold.it/140x100" alt="" />
      </figure>
    </div>
    <ul>
      <li>Item 1</li>
      <li>Item 2</li>
      <li>Item 3</li>
      <li>Item 4</li>
      <li>Item 5</li>
      <li>Item 6</li>
    </ul>
  </nav>
</aside>
<header>Header Centered</header>
<div class="container">
  <section>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
    <div>Scroll</div>
  </section>
</div>

Related


Fixed sidebar menu on left and fixed header on top

Pedro So what I want to do is a fixed sidebar with a fixed menu at the top and scrollable content in the middle. body, html { height: 100%; margin: 0; } aside { background: #90EE90; height: 100%; left: 0; position: fixed; top: 0; width: 120px;

Fixed sidebar menu on left and fixed header on top

Pedro So what I want to do is a fixed sidebar with a fixed menu at the top and scrollable content in the middle. body, html { height: 100%; margin: 0; } aside { background: #90EE90; height: 100%; left: 0; position: fixed; top: 0; width: 120px;

Fixed sidebar menu on left and fixed header on top

Pedro So what I want to do is a fixed sidebar with a fixed menu at the top and scrollable content in the middle. body, html { height: 100%; margin: 0; } aside { background: #90EE90; height: 100%; left: 0; position: fixed; top: 0; width: 120px;

Fixed sidebar menu on left and fixed header on top

Pedro So what I want to do is a fixed sidebar with a fixed menu at the top and scrollable content in the middle. body, html { height: 100%; margin: 0; } aside { background: #90EE90; height: 100%; left: 0; position: fixed; top: 0; width: 120px;

Bootstrap fixed sidebar and header

parser I'm trying to pin the sidebar in bootstrap along with the navbar and header. I have the following structure: <html> <head>...</head> <body> <div class="page-header custom-header"> <center> <h1>Example Pa

Bootstrap 4 fixed top navigation and fixed sidebar

username This is a good example of how to create a navbar using a sidebar. Can anyone modify the code so that the top navigation is fixed at the top and the sidebar is fixed/static only if the main page content is scrolled? I can get the nav's top of the navig

Bootstrap 4 fixed top navigation and fixed sidebar

username This is a good example of how to create a navbar using a sidebar. Can anyone modify the code so that the top navigation is fixed at the top and the sidebar is fixed/static only if the main page content is scrolled? I can get the nav's top of the navig

Bootstrap 4 fixed top navigation and fixed sidebar

username This is a good example of how to create a navbar using a sidebar. Can anyone modify the code so that the top navigation is fixed at the top and the sidebar is fixed/static only if the main page content is scrolled? I can get the nav's top of the navig

Fixed top bar + 100% height fixed sidebar?

f1nn I would like to know how to make proper layout for fixed navbar markup with sidebar. What I want to archive: Fixed navbar Fixed right column (side column) Liquid left column (content) Sidebar Sidebar height is always 100% of widnow height (except navbar).

Bootstrap CSS: fixed left sidebar

low coupling I'm working on a Bootstrap css based webpage and I want to be similar to the Bootstrap Dashboard example. The problem I'm having is that the section on the right side of the fixed sidebar on the left scrolls horizontally, while I want it to be fix

Semantic ui fixed menu in sidebar

Guillaume I tried (so far unsuccessfully) to set up a sidebar with a fixed menu inside. example: <div class="ui vertical right sidebar"> <div class="ui top pointing menu fixed"> <a class="active item">Infos</a> </div> <div class="ui segment" style='p

Semantic ui fixed menu in sidebar

Guillaume I tried (so far unsuccessfully) to set up a sidebar with a fixed menu inside. example: <div class="ui vertical right sidebar"> <div class="ui top pointing menu fixed"> <a class="active item">Infos</a> </div> <div class="ui segment" style='p

Semantic ui fixed menu in sidebar

Guillaume I tried (so far unsuccessfully) to set up a sidebar with a fixed menu inside. example: <div class="ui vertical right sidebar"> <div class="ui top pointing menu fixed"> <a class="active item">Infos</a> </div> <div class="ui segment" style='p

Semantic ui fixed menu in sidebar

Guillaume I tried (so far unsuccessfully) to set up a sidebar with a fixed menu inside. example: <div class="ui vertical right sidebar"> <div class="ui top pointing menu fixed"> <a class="active item">Infos</a> </div> <div class="ui segment" style='p

Fixed menu aligned to the left

username I work on this site . I have a fixed menu at the top of the page so that the user can view the menu at any time without scrolling. I added css to the menu class to reduce the width. #masthead { margin: 0 auto; width: 86%; } Now I get the fixed menu

Top menu does not push from left to right due to fixed position

Naren Velma I have a problem with sidebar menu push. I have 2 menus top menuand left menu. Now when I click on the hamburger menu to the left of the top menu, the sidebar will show. Note, however, that when the sidebar is displayed, it will push content from l

Flip menu with fixed top menu

username I have a question. I need to implement a rollover menu, but on the Internet I only find examples using CSS transitions and vendor prefixes. But all the examples show divs that are not fixed, the css below has a fixed menu (copied and pasted code and r

CSS: fixed/fixed top menu bar

User 1967599 I read many questions about this on SO but didn't really find what I was looking for. I have simple HTML and CSS code below. What I want to do is put the scrollbar only on the "left_content" DIV. As you can see in the example, it's now on the "lef

CSS: fixed/fixed top menu bar

User 1967599 I read many questions about this on SO but didn't really find what I was looking for. I have simple HTML and CSS code below. What I want to do is put the scrollbar only on the "left_content" DIV. As you can see in the example, it's now on the "lef

Menu toggle fixed left and right

Carlos Eduardo I would like to create an effect by clicking on a link "click", the sidebar that appears, and appears in this "container" with a soft effect, showing from right to left. If possible and vice versa, click the menu from left to right, eg "Item 1".

Fixed menu on the left with scrollable content

Jonathan Frosino I want a menu that is fixed on the left and its content is scrollable on the right. All I want to do is this site : http://other.wpengine.com/ The menu is fixed and the content is scrollable. Can you guys help me? Thanks in advance! rosy Take

Menu toggle fixed left and right

Carlos Eduardo I would like to create an effect by clicking on a link "click", the sidebar that appears, and appears in this "container" with a soft effect, showing from right to left. If possible and vice versa, click the menu from left to right, eg "Item 1".

Menu toggle fixed left and right

Carlos Eduardo I would like to create an effect by clicking on a link "click", the sidebar that appears, and appears in this "container" with a soft effect, showing right to left. If possible and vice versa, click the menu from left to right, eg "Item 1". I wa

sidebar not fixed

Yilan Ezerman (WS) First, this is the site I'm talking about: Be You.net is better So far so good, the problem is when I click on one of the categories in the right sidebar. I go to a new page like This Page , the problem is that the sidebar is not fixed like

Fixed header hide content on top

OñayM. Sheard I'm working on a website with a fixed header at the top. However, when I navigate to the anchor, the start content is hidden by the title. Is there a better way to offset the code I'm using. I think it has something to do with the following lines

Fixed header hide content on top

OñayM. Sheard I'm working on a website with a fixed header at the top. However, when I navigate to the anchor, the start content is hidden by the title. Is there a better way to offset the code I'm using. I think it has something to do with the following lines

Fixed header hide content on top

OñayM. Sheard I'm working on a website with a fixed header at the top. However, when I navigate to the anchor, the start content is hidden by the title. Is there a better way to offset the code I'm using. I think it has something to do with the following lines

Fixed header hide content on top

OñayM. Sheard I'm working on a website with a fixed header at the top. However, when I navigate to the anchor, the start content is hidden by the title. Is there a better way to offset the code I'm using. I think it has something to do with the following lines