使用display:table单元格降低h1上的高度



我使用display:table cell、vertical-align:middle和text-align:center在表格单元格中居中显示文本。然而,现在文本上方和下方有令人讨厌的间距。如何将其完全移除?我希望文本四周都没有空白。

PS-我试过border collapse: collapse,但似乎无法让它发挥作用。

(另请参阅下面的小提琴…)

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/

使用内联显示属性,如:

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

最新更新