javascript - CSS Dynamic Margin on Window Resize - Stack Overflow

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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745225100a4617424.html

相关推荐

  • javascript - CSS Dynamic Margin on Window Resize - Stack Overflow

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

    5小时前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信