链接和按钮定位

时间:2013-09-14 09:58:23

标签: html css button cross-browser positioning

我需要制作特定类的按钮和链接,以同样的方式定位和定位。我试过这个(简化):

<html>
    <head>
        <title>My site</title>
        <style>
            .my-class {
                display: inline-block;
                background-color: #cccccc;
                width: 18px;
                height: 18px;
                cursor:pointer;
                box-sizing: border-box;
                border: 1px solid #888888;
            }
        </style>
    </head>
    <body>

        <a href="#" class="my-class" title="My link"></a>

        <button class="my-class" type="submit" title="My button"></button>

    </body>
</html>

但链接的位置比按钮高一点:

buttons

是否有跨浏览器的css解决方案(没有javascript)允许将它们放在同一级别上?

3 个答案:

答案 0 :(得分:0)

试试这个Fiddle

这应该适合您的情况。它主要包括css的float属性

答案 1 :(得分:0)

将此添加到您的css:

vertical-align: middle;

你可以在这里看到:http://codepen.io/anon/pen/akzgy

或者您可以将显示设置为阻止并浮动到左侧:

display: block;
float: left;

答案 2 :(得分:0)

<body>
   <div style="height:50px;line-height:50px">
    <a href="#" class="my-class" title="My link"></a>

    <button class="my-class" type="submit" title="My button"></button>
    </div>


</body>

的CSS:

 .my-class {
            display: inline-block;
            background-color: #cccccc;
            width: 18px;
            height: 18px;
            cursor:pointer;
            box-sizing: border-box;
            border: 1px solid #888888;
            height:50px;
vertical-align:top;
        }