1

How does div sub set div center to middle? Text can be different, so margin or line-height in this situation is not a good solution.

CSS:

.center {
    background-color: #336699;
    width: 200px;
    height: 200px;
}

.sub {
    display: inline-block;
    vertical-align: middle;
}

HTML:

<div class="center">
    <span class="sub">
        Some text text...
    </span>
</div>
Ondrej Slinták
  • 30,448
  • 20
  • 91
  • 125
user319854
  • 3,810
  • 13
  • 40
  • 44

1 Answers1

3

A possible solution is:

HTML

<div class="center">
    <span class="sub">
        Some text text...<br />
        An some more text...
    </span>
</div>

CSS

.center
 {
     background-color: #336699;
     width: 200px;
     height: 200px;
     display: table;
 }

.sub
 {
     display: table-cell ;
     vertical-align: middle;
     text-align: center;
 }

A live demo, if needed, are at http://jsfiddle.net/vladsaling/6nTGF/.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
vlad saling
  • 375
  • 2
  • 9