Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Center a div within an asp.net content placeholder 1

Status
Not open for further replies.

dvannoy

MIS
May 4, 2001
2,765
US
I'm trying to set a div to to 100% hieght and to the center of the content placeholder in my asp.net masterpage. I can't seem to get it to work.

my css is below

any help woudl be appreciated

.maindiv {
position:fixed center !important;
display:inline-block;
background-color: #FFFFFF;
width: 700px;
height: 100%;

}

#placeholder {
position: center;
border: 1px solid #fafafa;
background-color: #E0E0E0;
margin: 0 auto;
width: 100%;
min-height: 750px;

}
 
Center" is not a valid value for the position attribute in CSS. There is no such thing as a centered position.

The valid values for the position attribute are Fixed, Relative, Absolute and Static. With static being the default position if no styling is applied.

If you want to center horizontally, you can use margins on a relatively or statically positioned element.

Code:
div
{
   margin-left:auto;
   margin-right:auto;
}

This will center the block level element such as div horizontally within its parent.

To to center a block level element vertically is a little harder. And will depend on the general layout you are working with.

Normally, padding can be used, but in really large empty parents this harder to do since you would need a lot of padding.

A couple of options for different layouts and element displays.








----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top