.target {
position: absolute;
left: 50%; /* set left */
width: 500px; /* give width */
margin-left: -250px; /* margin-left = width/2 */
}
并将其父级设为position: relative
<强> DEMO 强>
示例jQuery方法:
var width = $('.target').width();
$('.target').css({
left: '50%',
'margin-left': -(width / 2)
});
<强> DEMO 强>