Jump to content

CSS Uber Centering

Whether you're a seasoned veteran or a struggling beginner, Web Radiance is the web development and web design forum for you. You'll find answers to all your HTML, CSS, SEO, and Programming needs. Pull up a chair and stay awhile.

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

CSS Uber Centering Rate Topic: -----

#1 User is offline   moojoo 

  • Argh!
  • Group: Members
  • Posts: 449
  • Joined: 03-August 06
  • Location:Texas

Posted 01 December 2006 - 11:37 AM

Just thought I would stick this in here as I did in WF because some person said it was impossible with CSS :angry2:

This example shows how to set a fixed width box centered both vertically and horizontally with just CSS.It works simply by using absolute positioning of 50% and then using negative margins 1/2 the width and height of the object to compensate. Tested in IE 6, 7, FF, Safari etc.. This can also be done with percentages but that method however takes a bit more lovin to get it to behave in IE.

Working Example


#container {
width:400px;
height:200px;
position:absolute;
top:50%;
left:50%;
margin:-100px 0 0 -200px;
border:solid 1px #CCCCCC;
padding:8px;
overflow:auto;
}


Yup! Its that easy! :wub:

This post has been edited by moojoo: 01 December 2006 - 11:39 AM

Its not girly, its web 2.0!
0

#2 User is offline   marcamos 

  • W.R. General
  • Group: Administrators
  • Posts: 2,849
  • Joined: 04-April 06
  • Gender:Male
  • Location:Massachusetts - USA

Posted 01 December 2006 - 11:46 AM

Yep, that is exactly how I do it!
0

#3 User is offline   Karl Buckland 

  • A.K.A. Sirkent
  • Group: Administrators
  • Posts: 2,145
  • Joined: 04-April 06
  • Gender:Male
  • Location:Kent, UK

Posted 01 December 2006 - 02:53 PM

View Postherkalees, on Dec 1 2006, 04:46 PM, said:

Yep, that is exactly how I do it!


At least is is now, eh? :P
QUOTE(benbramz @ Aug 17 2007, 07:44 AM) Ive noticed that quite a few people are now adding quotes from the board into their signature. I think its started an new web-radiance craze.. :P
0

#4 User is offline   Ben Abrams 

  • The buddy system:never fails
  • Group: Administrators
  • Posts: 1,850
  • Joined: 04-April 06
  • Gender:Male

Posted 01 December 2006 - 03:07 PM

nice example!

View PostSirkent, on 21 September 2007 - 04:26 AM, said:

<monty python high-pitched female voice>I DON'T LIKE SPAM!</monty python high-pitched female voice>
0

#5 User is offline   James Mitchell 

  • Legendary
  • Group: Administrators
  • Posts: 922
  • Joined: 26-July 06
  • Gender:Male
  • Location:Fort Wayne, IN

Posted 02 December 2006 - 12:38 AM

great example - thanks Mark
Posted Image
0

#6 User is offline   TJSingleton 

  • Allegedly Legendary
  • Group: Members
  • Posts: 517
  • Joined: 31-July 06
  • Location:Winder, GA

Posted 02 December 2006 - 01:13 AM

Clever, is this something new? or an old trick you've been keeping from us?
0

#7 User is offline   benbacardi 

  • Administrator
  • Group: Administrators
  • Posts: 1,140
  • Joined: 06-April 06
  • Gender:Male
  • Location:United Kingdom

Posted 02 December 2006 - 06:39 AM

That is so useful!! I've been looking for a way to center things vertically with CSS for ages...
0

#8 User is offline   Ben Abrams 

  • The buddy system:never fails
  • Group: Administrators
  • Posts: 1,850
  • Joined: 04-April 06
  • Gender:Male

Posted 02 December 2006 - 11:24 AM

moojoo = harry potter for CSS

View PostSirkent, on 21 September 2007 - 04:26 AM, said:

<monty python high-pitched female voice>I DON'T LIKE SPAM!</monty python high-pitched female voice>
0

#9 User is offline   marcamos 

  • W.R. General
  • Group: Administrators
  • Posts: 2,849
  • Joined: 04-April 06
  • Gender:Male
  • Location:Massachusetts - USA

Posted 02 December 2006 - 11:49 AM

Not to sounds like a horse's rear end, but I thought most people knew this?

[ducks and hides]
0

#10 User is offline   TJSingleton 

  • Allegedly Legendary
  • Group: Members
  • Posts: 517
  • Joined: 31-July 06
  • Location:Winder, GA

Posted 02 December 2006 - 11:51 AM

:D To be honest, I've never needed to center vertical-- maybe a splash screen
0

#11 User is offline   benbacardi 

  • Administrator
  • Group: Administrators
  • Posts: 1,140
  • Joined: 06-April 06
  • Gender:Male
  • Location:United Kingdom

Posted 02 December 2006 - 11:51 AM

Well maybe I live in a world of my own!!
0

#12 User is offline   TJSingleton 

  • Allegedly Legendary
  • Group: Members
  • Posts: 517
  • Joined: 31-July 06
  • Location:Winder, GA

Posted 02 December 2006 - 03:35 PM

What's WF?

Also, Jon Hicks suggests

Quote

Instead of making the negative margin exactly half the height of the main content, give it 10px more. Its a picture framing trick, as centering it exactly can make it feel as if it’s ‘falling off the page’.

http://www.hicksdesign.co.uk/journal/verti...with-a-shiv-div

(More catching-up-on-feeds goodness :D_
0

#13 User is offline   marcamos 

  • W.R. General
  • Group: Administrators
  • Posts: 2,849
  • Joined: 04-April 06
  • Gender:Male
  • Location:Massachusetts - USA

Posted 02 December 2006 - 03:39 PM

Yeah, Hicks is the man.

WF is an older web design forum that moojoo moderates, and is the same one us Admins came from before we started webradiance.

Here is a deserved link: http://www.webforumz.com
0

#14 User is offline   TJSingleton 

  • Allegedly Legendary
  • Group: Members
  • Posts: 517
  • Joined: 31-July 06
  • Location:Winder, GA

Posted 02 December 2006 - 03:48 PM

10-4 -- But I try to stay away from things that are counter-productive -- like web forums! :D (just kidding of course -- but I seriously could be working.)
0

#15 User is offline   william 

  • SEO Specialist
  • Group: Members
  • Posts: 233
  • Joined: 13-October 06
  • Gender:Male
  • Location:Gloucestershire, UK
  • Interests:SEO, Web Design, PHP Development, Wordpress, Fireworks, Photoshop, EpiServer

Posted 03 December 2006 - 09:06 AM

Good skills :ninja:
0

#16 User is offline   Ryan Fait 

  • W.R. Sergeant
  • Group: Members
  • Posts: 204
  • Joined: 07-January 07
  • Location:Las Vegas

Posted 08 January 2007 - 02:58 PM

That's the method I use, the only problem is that you need to make sure it's not too wide. With the negative margin and absolute positioning, it the lefthand side will just slide off the page (even with min-width set).

Quote

This can also be done with percentages but that method however takes a bit more lovin to get it to behave in IE.


Forgot to ask, but what do you mean by percentages? Like in the margin..?
The commercial front for my freelance web design company.
0

#17 User is offline   moojoo 

  • Argh!
  • Group: Members
  • Posts: 449
  • Joined: 03-August 06
  • Location:Texas

Posted 12 January 2007 - 09:28 AM

No you can use % values for the width/height to make the centered layout flexible. Here is a mostly complete example:

http://www.newguyinennis.com/samples/uber_...ring_fluid.html

and of course the static example:

http://www.newguyine..._centering.html

This post has been edited by moojoo: 12 January 2007 - 09:29 AM

Its not girly, its web 2.0!
0

#18 User is offline   Ryan Fait 

  • W.R. Sergeant
  • Group: Members
  • Posts: 204
  • Joined: 07-January 07
  • Location:Las Vegas

Posted 12 January 2007 - 08:04 PM

Okay. Are you going to leave those links up permanently?
The commercial front for my freelance web design company.
0

#19 User is offline   moojoo 

  • Argh!
  • Group: Members
  • Posts: 449
  • Joined: 03-August 06
  • Location:Texas

Posted 16 January 2007 - 01:19 PM

Yes and I add more when I can. I also welcome ideas as I love to try out experiments and figure out how to make things happen with CSS.

http://www.newguyinennis.com/samples/

This post has been edited by moojoo: 16 January 2007 - 01:22 PM

Its not girly, its web 2.0!
0

#20 User is offline   Ryan Fait 

  • W.R. Sergeant
  • Group: Members
  • Posts: 204
  • Joined: 07-January 07
  • Location:Las Vegas

Posted 17 January 2007 - 07:47 AM

Cool! I've got them bookmarked :D
The commercial front for my freelance web design company.
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users