开发者

centering of content (css)

开发者 https://www.devze.com 2023-03-30 06:46 出处:网络
I just can\'t seem to figure this out - I\'m trying to get the top section (class=top) to center regardless of screen resolution.

I just can't seem to figure this out - I'm trying to get the top section (class=top) to center regardless of screen resolution.

Can anyone offer any advice开发者_如何学JAVA please?

EDIT: hahah sorry! I completly forgot the link!! :)

  • linked removed

Thanks,

Michael


It slightly depends on your site structure, but if you mean horizontal centering setting a horizontal margin of auto should work.

margin: auto; /* will set vertical margin as well, but this won't have an effect */

If you are talking about vertical centering it's a lot more complicated:

http://blog.themeforest.net/tutorials/vertical-centering-with-css/

Edit: you added a link to your site

In your specific case, setting the margin of .top to auto won't cut it because of two reasons:

  1. .top has a width of 100% because it's a block-level element.
  2. .top needs this width of 100% because of the background color

To fix this, add another div within .top, give this div a fixed width that is wide enough to contain all the content (it seems you need 1124px) and give this div the margin:auto.


Set the css margin attribute..

margin: 0 auto;


You forgot to link your website but if you're trying to center a div inside its parent horazontally you can use this:

.top{ margin:0 auto; }

<div class="top">content</div>
0

精彩评论

暂无评论...
验证码 换一张
取 消