I've got a box with a fixed size and two elements in it, an image and some text. Both are variable in it's widths and heights, an I'm trying to vertically align the text within the remaining space under the image.
|-------- 184px --------|
(text-align:center)
+-----------------------+ - -
| +-------+ | | |
| |#######| | | |
| |#######| | | | ?
| |#######| | | 1 |
| +-------+ | | 6 |
| - - - - - - - - - - - | | 8 -
| | | p |
| Some vertically | | x |
| aligned text with | | | *
| variable length | | |
| | | |
+-----------------------+ - -
line-height
can't be used, as the text may have up to three linesvertically-align
seems to only work on a fixedheight
- JavaScript always returns
height:0
forimg
(a pure CSS solution be preferred anyway)
The HTML:
<div class="box boxed js-box">
<img src="/images/box-icon1.png">
<span class="text short js-box-text">
Title
</span>
<span class="text long js-box-text">
Detailled description when hovered
</span>
</div>
The style:
.box {
background: #FFF;
cursor: default;
height: 168px;
margin-top: 30px;
padding: 4px;
text-align: center;
width: 184px;
}
.box img {
border: 0;
display: block;
margin: auto;
margin-bottom: 24px;
position: relative;
top: 16px;
width: 76px;
}
.box .text {
bottom: 4px;
font-size: 12px;
position: relative;
}
.box .text.short {
font-size: 16px;
top: 8px;
}
.box .text.long {
display: none;
font-size: 14px;
}