0

I centered text in a table cell using display: table-cell, vertical-align: middle, and text-align: center. However, there is annoying spacing above and below the text now. How can I remove it completely? I want zero margin/padding all around the text.

PS- I've tried border collapse: collapse and can't seem to get it to work.

(also see fiddle below...)

HTML:

  <body>
    <div>
    <h1><a href=#>H</a></h1>
    <h1><a href=#>E</a></h1>
    <h1><a href=#>L</a></h1>
    <h1><a href=#>L</a></h1>
    <h1><a href=#>O</a></h1>
    </div>
  </body>

CSS:

    body {
        font-family: 'Sigmar One', cursive;
        font-size: 100px;
        color: white;
        text-shadow: 4px 4px 4px #000;

        background-color:blue;

        width: 100%;
        height: 100%;
        margin: 0;
    }


    div {
        position:absolute; 
        height:100%; 
        width:100%;
        display: table;
    }

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

    a:visited, a:active {
        text-decoration: none;
        color: white;
    }

    a:link {
        text-decoration: none;
            color: white;
        text-shadow: 0px 2px 3px rgba(255,255,255,.25);
        -webkit-background-clip: text;
           -moz-background-clip: text;
                background-clip: text;
    }

    a:hover {
        text-shadow: 4px 4px 4px #000;
        color: white;
    }

http://jsfiddle.net/8Huu7/8/

neuquen
  • 3,991
  • 15
  • 58
  • 78
  • Is the text "hello" to be displayed as a single line or as a vertical column one character wide? You typeset "hello" as a column. – Marc Audet Aug 12 '13 at 01:46
  • @MarcAudet I plan on making each one a link. I typset it that way for readability. I want it all to be on one row. Just updated it to reflect those changes. – neuquen Aug 12 '13 at 01:52
  • Could one wrap the links in a wrapper element? – Marc Audet Aug 12 '13 at 01:59
  • Sure. I actually tweaked it so that each link is inside of a separate h1. But it can be inside of a span/div. Whatever makes it work. PS- I just updated the question to reflect the tweaks. – neuquen Aug 12 '13 at 02:01

1 Answers1

0

use the inline display property like so:

h1 {
        display: table-cell;
        vertical-align: middle;
        text-align:center;
        display: inline;
    }
Bit68
  • 1,446
  • 10
  • 25