INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Center a div within an asp.net content placeholder

Center a div within an asp.net content placeholder

(OP)
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;

}

RE: Center a div within an asp.net content placeholder

"Center" is not a valid value for the position attribute in CSS. There is no such thing as a centered position.
http://www.w3schools.com/css/css_positioning.asp

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.

http://vanseodesign.com/css/vertical-centering/







----------------------------------
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close