Vertical Centering a block in IE7

后端 未结 4 501
滥情空心
滥情空心 2021-01-14 03:07

I\'m trying to get vertical centering a block in IE7 (IE6 if possible too), let me get one thing clear - I\'m not vertically centering the actual element, but the text with

4条回答
  •  [愿得一人]
    2021-01-14 03:29

    If you know it will be just one line of text, use line-height.

    It is far from a single element, but you could just use an actual table cell. It's ugly, but supporting IE6 is an ugly affair.

    table {
        border: 0;
        border-collapse: collapse;
        height: 54px;
        width: 100px;
    }
    td {
        vertical-align: middle;
    }
    a {
        background: black;
        color: white;
        display: block;
        height: 100%;
        text-align: center;
        text-decoration: none;
    }
    
    
    Hello superlongword

    If you know the link will be a certain number of lines, you can center using one extra element and a margin. (e.g. anchor text, em { margin-top:12px })

    If you don't know the height of the element to be centered, you need table-cell layout behavior. The only way to get this in IE6 is with an actual table cell or JavaScript. Sorry.

提交回复
热议问题