Skip to content Skip to sidebar Skip to footer

Page Content Appearing Underneath Sidebar

I am creating a html layout with a sidebar. But my header and content are appearing underneath my sidebar instead of next to it. Thanks

Solution 1:

Add "display: inline-block;" to the elements that you want to display next to each other.

Solution 2:

Just add

#sidebar {float:left;
}

.container { position:relative; padding:10px; top:0px; right: 0; left: 0; height: 1200px;}
#sidebar {
    position:relative;
    top:0; bottom:0; left:0;
    width:200px;
    height: 1000px;
    background: gray;
    float:left;
}

#header { border:1px solid #000; height:300px; 
    padding:10px; margin-left: 200px;
}
#content { border:1px solid #000; height:700px; margin-left: 200px;;
    padding:10px; 
}
<divclass="container"><divid="sidebar"><ahref="#"> Link1 </a></div><divid="header"><h2class="title">Title</h2><h3>Header content</h3></div><divid="content"><center><p>Hello</p></center></div></div>

Solution 3:

You should try to change your position: relative; to position: absolute;. You can then adjust the position of your divs using a margin.

.container { 
  position:relative;
  padding:10px;
  top:0px;
  right: 0;
  left: 0;
  height: 1200px;
 }
 
#sidebar {
    position:absolute;
    top:0; bottom:0; left:0;
    width:200px;
    height: 1000px;
    background: gray;
}
    
#header { border:1px solid #000; height:300px; 
    padding:10px; margin-left: 200px;
    margin-top:-10px;

}

#content {
  border:1px solid #000;
  height:700px;
  margin-left: 200px;
  padding:10px; 
}
<divclass="container"><divid="sidebar"><ahref="#"> Link1 </a></div><divid="header"><h2class="title">Title</h2><h3>Header content</h3></div><divid="content"><center><p>Hello</p></center></div></div>

Working fiddle: https://jsfiddle.net/khs8j3gu/2/

Good luck!

Solution 4:

I have introduced .inner-container and defined two flexboxes. CSS is simplified.

* {
  box-sizing: border-box;
}

.container {
  display: flex;
}

.inner-container {
  display: flex;
  flex-flow: column;
  width: 80%;
}

#sidebar {
  width: 20%;
  background: gray;
}

#header {
  border: 1px solid black;
  height: 300px;
  padding: 10px;
}

#content {
  border: 1px solid black;
  padding: 10px;
}
<divclass="container"><divid="sidebar"><ahref="#"> Link1 </a></div><divclass="inner-container"><divid="header"><h2class="title">Title</h2><h3>Header content</h3></div><divid="content"><center><p>Hello</p></center></div></div></div>

Solution 5:

you should just try editing the

position: fixed

this will solve your problem.

Post a Comment for "Page Content Appearing Underneath Sidebar"