CSS Center Align

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
User avatar
Pazuzu156
Forum Contributor
Posts: 241
Joined: Sat Nov 20, 2010 9:00 pm
Location: GA, USA
Contact:

CSS Center Align

Post by Pazuzu156 »

Okay, here is the dilemma. I have this div element, an error. Well...a response. When the response is shown using jQuery, it will come from the top of the webpage, and disappear after 5 seconds. I have it at the top, but I want it to be dead in the center, but have it where when users with different screen resolutions can also see it in the center. Here is my CSS code for the entire thing:

Code: Select all

#response { 
    -moz-border-radius-bottomleft:6px;
    -moz-border-radius-bottomright:6px;
    -webkit-border-bottom-left-radius:6px;
    -webkit-border-bottom-right-radius:6px;
    width:220px; padding:5px;
    text-align:center;
    position:absolute;
    left:??;
    top:0;
}
Any help would be greatly appreciated.
- Kaleb Klein
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
darek
Forum Newbie
Posts: 8
Joined: Tue Apr 19, 2011 2:26 am
Location: Opole, Poland

Re: CSS Center Align

Post by darek »

You need to change jQuery code. Just get browser height, subtract your div height and divide result by two. That's how you get top position of your div. There's no css code that will align your div in center. You can't center your div the way you want, just by changing css.
Post Reply