开发者

CSS Dynamic Margin on Window Resize

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 Javascr开发者_开发问答ipt?

Thanks,

Kory


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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜