-1

I'm trying to get my webpage to expand horizontally to fit any browser window but still have the content centered in the middle of the page. I managed to do one or the other but cannot for the life of me figure out how to make both work at the same time. If I set width and height to 100% and have the body margins set to 0 auto it works great but then my content is no longer centered and all the divs end up overlapping each other. However, if I set the width to 900px then it's all centered and looks great. But there's white space around it because it's not expanding to fit the browser window.

Can anyone let me know the trick to making this work? I want it to look like this page where the sides expand to fit the browser but all the content remains centered in the middle:

Also, here is my CSS:

<style type="text/css">
body {
text-align:center;
margin:0px; 
padding:0px;
width:100%;
height:100%;
}

body#home a#nav-home,
body#resume a#nav-resume,
body#portfolio a#nav-portfolio,
body#contact a#nav-contact
{
color: #dfadec;
text-decoration:none;
}

#container {
background-color:#eae5e5;
width:900px;
text-align:left;
margin: 0 auto;
height:auto;
}

#main {
padding-top:200px !important;
padding-bottom:120px !important;
width:900px;
margin-left: auto;
margin-right:auto;
}

#header {
position:fixed;
border-top:solid 15px #4d4d4f;
font-family:Open Sans;
font-size:30px;
color:#4d4d4f;
background-color:#FFF;
width:900px;
padding-bottom:45px;
}

#title {
padding-top:30px;
position:absolute;
margin-left:60px;
}

#footer {
color:#FFF;
position:fixed;
font-family:Open Sans;
font-size:12px;
background-color:#dfadec;
width:900px;
padding-bottom:45px;
padding-top:45px;
margin: 0 auto;
height: auto;
}

#nav {
padding-top:70px;
font-size:12px;
color:#CCC;
margin-left:570px;
}

#nav a:link {
color:#CCC;
text-decoration:none;
}

#nav a:hover {
color:#dfadec;
text-decoration:none;
}

h1 {
font-size:60px;
font-family:Open Sans;
color:#4d4d4f;
margin-top:-150px;
}

h2 {
font-size:40px;
font-family:Open Sans;
color:#4d4d4f;
font-weight:normal;
margin-top:-40px;
}

#resume {
background:#5c5c54;
width:130px;
height:130px;
font-family:Open Sans;
color:#FFF;
margin-left:5px;
text-align:center;
position:absolute;
-webkit-transition-property:color, background; 
-webkit-transition-duration: 0.5s; 
-webkit-transition-timing-function: linear, ease-in; 
}

#resume p {
vertical-align:middle;
padding-top:45px;
font-size:12px;
}

#resume:hover {
background-color:#373732;
color:#FFF;
}

#work {
background:#dfadec;
width:130px;
height:130px;
font-family:Open Sans;
color:#FFF;
margin-left:150px;
text-align:center;
position:absolute;
-webkit-transition-property:color, background; 
-webkit-transition-duration: 0.5s; 
-webkit-transition-timing-function: linear, ease-in; 
}

#work p {
vertical-align:middle;
padding-top:45px;
font-size:12px;
}

#work:hover {
background-color:#705676;
color:#FFF;
}

#skills {
background:#4d4d4f;
width:130px;
height:130px;
font-family:Open Sans;
color:#FFF;
margin-left:295px;
text-align:center;
position:absolute;
-webkit-transition-property:color, background; 
-webkit-transition-duration: 0.5s; 
-webkit-transition-timing-function: linear, ease-in; 
}

#skills p {
vertical-align:middle;
padding-top:45px;
font-size:12px;
}

#skills:hover {
background-color:#262628;
color:#FFF;
}

img#icon {
background-color:#4d4d4f; 
padding:12px;
}

#intro {
width: 400px;
font-family: Open Sans;
font-size: 12px;
color: #4d4d4f;
margin-left: 320px;
position: absolute;
left: 500px;
top: 522px;
text-align:justify;
}

</style>

Any suggestions? Please let me know. And let me know if I need to post the HTML too.. I just figured the problem was in the CSS since that's where I'm defining width, etc.

Thanks!

Pooja

Pooja CL
  • 61
  • 2
  • 9
  • possible duplicate of [How to center a div in a div - horizontally?](http://stackoverflow.com/questions/114543/how-to-center-a-div-in-a-div-horizontally) – SlightlyCuban Aug 26 '13 at 19:46
  • Your screenshot is a broken link, and your markup would indeed be helpful. Please consider creating a JSFiddle. – Mister Epic Aug 26 '13 at 22:16
  • If you have not yet heard about Responsive web design, I suggest doing some reading on it. This will not directly answer your question, but it seems like it might be helpful for you, based on your question. http://coding.smashingmagazine.com/2011/01/12/guidelines-for-responsive-web-design/ – SunSparc Aug 26 '13 at 22:21
  • Thanks for all these suggestions! SlightlyCuban directed me to the discussion I had been searching for.. that was exactly what I wanted to do. So thank you for that! The only issue I'm now having is that I'm not sure if I position certain divs (not the ones I needed to be 100% width) absolutely if that will screw up the resizing based on browser. Does anyone know if that would be affected? Oh, and I updated the screenshot link. It should work now. – Pooja CL Aug 28 '13 at 20:37

2 Answers2

1

Try something like this -- basic CSS that keeps the content centered vertically and horizontally.

http://coding.smashingmagazine.com/2013/08/09/absolute-horizontal-vertical-centering-css/

Jared
  • 562
  • 1
  • 6
  • 22
0

try this

<table align="center" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td valign="top" width="70%">right</td>
<td valign="top" width="30%">left</td>
</tr>
</table>
Mahmoud Samy
  • 270
  • 2
  • 11