Jump to content

Trying to center auto expanding div


kaosjon

Recommended Posts

Hi i am trying to center a div that auto expands depending on the content, however the div must be fixed positioned with a background that can also expand and contract with the div. I have gotten pretty far with the coding of this, however have struck a problem that i can't seem to fix. So far the div expands and contracts depending on the content and is fixed positioned, but it is not centered and won't center for some reason.

 

Here is the html

 

<div id="accountBar">
<div id="accountContent">sdfsdfsdffsdf</div><!---end accountContent--->
</div><!--- end accountBar--->

 

Here is the css

 

#accountBar {

height: 56px;
width: 100%;
border: thin dotted #333;
margin-top: 56px;
margin-right: auto;
margin-bottom: 0;
margin-left: auto;
position: fixed;
}
#accountBar #accountContent {
height: 56px;
margin-top: 0;
margin-right: auto;
margin-bottom: 0;
margin-left: auto;
background-image: url(../images/accountBar.png);
background-repeat: repeat-x;
display: inline-block;
padding-right: 10px;
padding-left: 10px;
}

 

Thanks for any help you can give

Link to comment
Share on other sites

Expanding horizontally or vertically? And which div do you want to center - the div you have set with a fixed position is set to 100% width, so it's always going to take up the whole width of the screen, and cannot center.

 

Hi, thanks for the reply, the div i want to center is #accountContent and i want it to expand horizontally. Is there anything i can do to make this work?

 

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.