I have 2 div: one parent and one child. User can add this div with button click and they set the text value. I want to display these dives in border inline-block(3 items in 1 row, like new tabs in chrome). And I want to display this text in the center of border.
There is css code:
.parentDiv {
width: 300px;
height: 200px;
margin: 5px;
border: solid 1px black;
display: inline-block;
font-size: 24px;
}
.childDiv {
text-align: center;
vertical-align:middle;
}
Here’s a jsfiddle to show you a solution: http://jsfiddle.net/nfLu3/
the keys are:
line-heightof the parent container to its height (200px) and thetext-aligntocenter. So some text appears exactly in the middle of your box.displayasinline-block. In this way it’s oriented at the text around (it’s important!). The text around (I mean the line breaks and spaces before the child container) has aline-heightof200pxand the child block hasvertical-align:middle, so it will be centered.there you go