开发者

How to get own attributes object into itself

开发者 https://www.devze.com 2023-03-15 14:24 出处:网络
there! I wanna center the div by horizontal. Now I have to use Javascript + CSS. It looks like this CSS:

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

精彩评论

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