简体   繁体   中英

vertical align link inside div

I've created some floating buttons and a link that fills the whole button. However, vertical alignment doesn't seem to apply - the link text always stays at the top of the button <li> .

Here's a fiddle example: 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;
    }

将锚点的line-height设置为DIV的line-height ,或将其设置为display: block否则您的宽度/高度值将不起作用

In your a tags use table-cell instead of float and change vertical-align to middle :

.TemplateButton > a {
  /*float: left; Remove this*/
  display:table-cell;    /*Add this*/
  vertical-align:middle; /*Change to middle*/
}

Check this Demo Fiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM