我正在尝试在其父级中垂直和水平地居中 div。
JSFIDDLE:http: //jsfiddle.net/pE5QT/
CSS:
.parent {
width: 200px;
height: 200px;
background-color:red;
}
.child {
height: 100px;
width: 100px;
background-color:yellow;
}
HTML:
<div class="parent"> b
<div class="child"> a </div>
</div>
Javascript:
var parent = $('.parent');
var parentDimensions = parent.height() * parent.width();
var child = $('.child');
var childDimensions = child.height() * child.width();
parent.html();
child.html(childDimensions);
我很想得到答案,但我也很想了解它背后的逻辑。