在css / html中的对齐按钮在一行水平w /文本? [英] Aligning buttons in css/html in one line horizontally w/ text?

查看:269
本文介绍了在css / html中的对齐按钮在一行水平w /文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何水平对齐我的按钮?除此之外,我想向这些按钮添加文本。这是我目前有的。

I would like to know how could I align my buttons horizontally? On top of that I want to add text to those buttons. This is what I currently have.

Html正文部分

<body>


        <div class="tile_div">
            <table class="tile_table">
                <tr>
                    <td>
                        <img class="tile_image" height="50px" width="100px" src="./images/button_left.png"/> 
                        <p class="tile_p">Button one</p>
                    </td>
                    <td>
                        <img class="tile_image" height="50px" width="100px" src="./images/button_left.png"/> 
                        <p class="tile_p">Button two</p>
                    </td>
                    <td>
                        <img class="tile_image" height="50px" width="100px" src="./images/button_left.png"/> 
                        <p class="tile_p">Button three</p>
                    </td>
                </tr>
            </table>
        </div>




</body>

CSS:

.tile_image {
float:left;
margin:0px;



}

.tile_image img{
position:absolute;
}

.tile_p{
text-align:center;
position:relative;
}

外观如下:
http://img580.imageshack.us/img580/8867/uo7i.png

我想让文本在按钮的中间,而不是在它们的下面。

I want the text to be in the middle of the buttons not below them.

谢谢。

编辑:

好吧,当我使用
src =./ images / button_left.png应该看起来:
http://img580.imageshack.us/img580/8867/ uo7i.png
但是当我使用background-image
时会发生:
http://img580.imageshack.us/img580/6127/yz4.png

推荐答案

表不应用于布局。我认为最好的方法是使用如下的浮动链接:

tables should not be used for layout. I think the best approach would be to use floated links like this:

<div class="tile_div">
    <a href="#">Button one</a>
    <a href="#">Button two</a>
    <a href="#" class="last">Button three</a>
    <div class="clear"></div>
</div>

CSS:

.tile_div a {
    display: block;
    float: left;
    height: 50px;
    width: 100px;
    margin-right: 5px;
    background-image: url(./images/button_left.png);
    text-align: center;
    line-height: 50px;
    text-decoration: none;
}

.title_div a.last {
    margin-right: 0;
}

.clear {
    clear: both;
}

JSFiddle

这篇关于在css / html中的对齐按钮在一行水平w /文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆