Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertically aligning text inside a span

Tags:

html

css

JSFiddle here - http://jsfiddle.net/2R36y/

Relevant span code -

CSS

nav ul li a span {
    font: 30px"Dosis", sans-serif;
    text-transform: uppercase;
    position: relative;
    left: 120px;
    width: inherit;
    height: inherit;
    display: none;
    text-align: left;
}

HTML

<nav>
    <ul>
        <li> <a href="#">
                <span>Home</span>
            </a>
        </li>
        <li> <a href="#">
                <span>About</span>
            </a>
        </li>
        <li> <a href="#">
                <span>Portfolio</span>
            </a>
        </li>
        <li> <a href="#">
                <span>Contact</span>
            </a>
        </li>
    </ul>
</nav>
like image 755
Narabhut Avatar asked Jul 31 '13 00:07

Narabhut


1 Answers

One way is by using display: table-cell; and vertical-align: middle; - you can also use line-height since the <span> has a fixed height.

nav ul li a:hover span {
    font: 30px"Dosis", sans-serif;
    text-transform: uppercase;
    position: relative;
    left: 120px;
    width: inherit;
    height: inherit;
    display: table-cell;
    vertical-align: middle;
    text-align: left;
}

http://jsfiddle.net/2R36y/1/

like image 76
Adrift Avatar answered Oct 05 '22 12:10

Adrift