我正在尝试创建一个语言栏放置器,它将显示指向我网站的其他版本的链接。到目前为止,我有:

<div id="lang_dropper_wrapper">
    <img src="http://www.chambresdhotesdev.org/new_design/blank.gif" class="sprite-luna">
    <b class="down_arrow" style="float: right;">&nbsp;</b>
    <div id="lang_dropper">
        <a class="smaller lang-en" href="#">English</a>
        <a class="smaller lang-fr" href="#"> French</a>
        <a class="smaller lang-es" href="#">Cases rurals</a>
        <a class="smaller lang-mobile" href="#">Mobile</a>
    </div>
</div>


...然后是CSS:

.lang-en:before, .lang-es:before, .lang-fr:before,.lang-mobile:before {
    content: ' ';
    /*background: url(/new_design/sprites-all-2.png) no-repeat;*/
    width: 32px;
    height: 26px;
    display: inline-block;
    margin-right: 20px;
}

.lang-en:before {
    background: green
}

.lang-es:before{
    background: red;
}

.lang-fr:before{
    background: yellow
}

.lang-mobile:before{
    background: maroon;
}

#lang_dropper a:link {
    display:block;
    padding: 5px 5px 5px 10px;
    font-size: 12px;
    line-height: 30px;
    text-align: middle;
}
#lang_dropper a:hover {
    text-decoration: none;
    background: #eee;
}
#lang_dropper {
    position: absolute;
    top: 28px;
    left: 0px;
    z-index: 10000000;
    /*display: none;*/
    float: left;
    min-width: 160px;
    padding: 5px 0px;
    margin: 2px 0px 0px;
    background-color: #FFF;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.2);
    background-clip: padding-box;
    width: 200px;
}
#lang_dropper_wrapper {
    position: relative;
    width: 45px;
    float: left;
    margin-right: 3px;
    margin-top: 2px;

}
#lang_dropper_wrapper:hover {
    cursor: pointer;
}


我实际上是为标志图标使用CSS精灵-因此其中带有:before的东西以及每个都有一个类的东西令人困惑。

我唯一剩下的问题-使出血点垂直对齐!

您可以在此处看到一个有效的示例:

http://codepen.io/anon/pen/BjQgRe

除了我希望文本与它们左侧的标志彩色图标垂直对齐之外,它的工作原理非常好

我已经尝试过各种方法,但无法使其正常工作。

有什么建议吗?

谢谢!

最佳答案

vertical-align:middle应用于内联块元素。

.lang-en:before, .lang-es:before, .lang-fr:before,.lang-mobile:before {
content: ' ';
width: 32px;
height: 26px;
display: inline-block;
margin-right: 20px;
vertical-align:middle; /* Add this style */
}


DEMO

关于css - 无法获得垂直对齐的链接,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34546391/

10-12 12:37