微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

html – div内的垂直对齐链接

我创建了一些浮动按钮和一个填充整个按钮的链接.但是,垂直对齐似乎不适用 – 链接文本始终位于按钮顶部< li>.

这是一个小提琴的例子:http://jsfiddle.net/su7nf/

<div id="ButtonContainer">
    <ul>
        <li>
            <div class="TemplateButton"><a href="http://www.google.com">Report an Issue</a></div>
        </li>
        <li>
            <div class="TemplateButton"><a href="http://www.google.com">Contact Us</a></div>
        </li>
        <li>
            <div class="TemplateButton"><a href="http://www.google.com">Enter Project</a></div>
        </li>
        <li>
            <div class="TemplateButton"><a href="http://www.google.com">Request Consultation</a></div>
        </li>
        <li>
            <div class="TemplateButton"><a href="http://www.google.com">How to Protect Yourself From Some Really Long Text</a></div>
        </li>
    </ul>
</div>
ul {
        list-style-type: none;
    }
    /* BUTTONS INSIDE TAB STYLING */

    #ButtonContainer {
        margin: auto;
        width: 100%;
        overflow: auto;
        padding-top: 10px;
        padding-bottom: 10px;
    }

    #ButtonContainer > ul {
            padding: 0;
            margin: 0;
    }

    #ButtonContainer > ul > li {
        display: inline-block;
        vertical-align: bottom;
    }

    .TemplateButton {
        overflow: auto;
        vertical-align: bottom;
    }

    .TemplateButton > a {
        width: 119px;
        height: 119px;
        padding: 15px;
        float: left;
        background-color: pink;
        margin-left: 3px;
        margin-right: 3px;
        vertical-align: bottom;
        text-align: center;
        font-size: 1.25em;
        border: 1px solid white;
        border-radius: 15px;
        -moz-border-radius: 15px;
    }

解决方法

在你的标签中使用table-cell而不是float并将vertical-align更改为middle:
.TemplateButton > a {
  /*float: left; Remove this*/
  display:table-cell;    /*Add this*/
  vertical-align:middle; /*Change to middle*/
}

检查这个Demo Fiddle

原文地址:https://www.jb51.cc/html/226066.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐