开发者

How can I create a dynamic CSS margin?

I could probably do this in PHP, but I would have to include the CSS into my PHP file. So, I have a parent div whose height always varies, and then I have a child div whose width: 100%; height: 100%; in that child开发者_Python百科 div, I have text. The problem is, I want to vertically center the text inside the ChildChild div.

#parentDiv {
width: 200px;
height: PHP generates this;
}
#Child {
width: 100%;
height: 100%;
}
#ChildChild {
margin: how do I do this?
}

<div id="ParentDiv">
<div id="Child">
<div id="ChildChild">
HELLO!
</div>
</div>
</div>


If your text is only going to be one line high, try setting line-height: 100%;. Otherwise, maybe try following the solution outlined here, which involves using the display: table-cell; property to allow the desired use of the vertical-align: middle; property.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜