Frage

I need to center link inside the div vertically and horizontally.

My CSS:

    .div {
       display:block;
       background:red;
       width:162px;
       height:168px;
    }
    .span { }
    .link { }

My HTML:

    <div class="div">
       <span class="span">
          <a href="#" class="link"> Text in middle </a>
       </span>
    </div>

Link: http://jsfiddle.net/pjWUC/

War es hilfreich?

Lösung

Based on the coding in your example, use:

Updated jsFiddle example - a element is centered vertically and horizontally.

.div {
    display:table;
    background:red;
    width:162px;
    height:168px;
}
.span {
    display:table-cell;
    vertical-align:middle;
    text-align:center;
}

Andere Tipps

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

Unfortunately, display:table-cell is not supported by IE according to this.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top