html - center div in css but keep off of left nav -


i trying center #content div`` on page has position:absolute #nav on left side. #nav comes out 400px left side of page (accounting <body> margin).

here's code centering of both divs:

#nav{     position: absolute;     display: inline-block;     width: 350px;     height: 800px;  }  #content{     position: absolute;     display: inline-block;     left: 0;     right: 0;     margin: auto;     width: 600px;     height: 1000px;     border: solid;     border-width: 1px; } 

this works fine enough, unless is, window becomes quite narrow, in case #content slides on #nav. there way center #nav on page, relative window size, still put limit on how far left can move while window gets smaller?

edit: see jsfiddle demo of situation here: jsfiddle.net/b2bcofyd/1/#&togetherjs=gti1uzdgxf [i've modified dimensions of divs make more legible in demo]

you can add minimum width body. adding stylesheet:

body {    min-width: 950px; /*350 + 600*/ } 

this way, scrollbars appear when window gets smaller 950px;

as alternative, can wrap content , nav in 1 div , center div.

<div id="wrapper">    <div id="nav"> </div>    <div id="content"> </div> </div> 
#wrapper {    width: 950px;    margin: 0 auto; } #nav {    float: left;    width: 350px; } #content {    float: left;    width: 600px; } 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -