最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - CSS Dynamic Margin on Window Resize - Stack Overflow

programmeradmin1浏览0评论

Can I dynamically ensure that the content always remains centered in the window pane on this website?

Right now it uses a static margin-left on the .items class, and it uses jquery tools.

/

Can I do it in just CSS or CSS and Javascript?

Thanks,

Kory

Can I dynamically ensure that the content always remains centered in the window pane on this website?

Right now it uses a static margin-left on the .items class, and it uses jquery tools.

http://andstones.ca/newsite/

Can I do it in just CSS or CSS and Javascript?

Thanks,

Kory

Share Improve this question asked Jun 14, 2010 at 20:51 KoryKory 3984 silver badges14 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

I didn't quite see what part you were talking about as it looks like most of it works just fine.

For auto-centering, you should use auto for margins:

margin: 0 auto;

Put that one whatever div you want centered.

Lets say that you want to center a container with 900px wide, the most cross browser way that I've used is:

div#container{
  width:900px;
  position:relative;
  left:50%;
  margin-left:-450px;
}

This goes to the center of the x axis and stays there regardless of other elements of that page! Of course that this only works with a fixed width and not a dynamic one!

If i remember correctly, you have to use the following in IE

text-align: center;

Even to center a div

发布评论

评论列表(0)

  1. 暂无评论