开发者

How to get own attributes object into itself

there!

I wanna center the div by horizontal. Now I have to use Javascript + CSS. It looks like this

CSS:

div#block {
   left: 50%;
}

JavaScript:

$('#block').css('margin-left', ($('#block').outerWidth()/2) + 'px');

Brobably, I can do like this:

div#block {
    left: 50%;
    margin-left: self -50%;
}

Thank a lot for you开发者_JAVA百科r help =)


<div id="blockparent"><div id="block"></div></div>

div#blockparent {
   width: 100%; /*or fixed width*/
}

div#block {
   margin: 0 auto;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜