对齐图标以选择标记

时间:2011-01-24 23:15:01

标签: css blueprint-css

我试图让自己的表格变得漂亮我不确定我在做什么。我有两个选择框和两组图标,我想像这样格式化:

^   +-------------+        +--------------+
|   |             |   <--  |              |
    |  Select 1   |   -->  |  Select 2    |
|   |             |        |              |
v   +-------------+        +--------------+

中间的左右图标将项目移入和移出选择框,左侧的向上和向下箭头移动选择1中的项目上下。什么是用css获得这种布局的简单方法?我已经能够用一张桌子来破解一些东西了,我对纯粹的CSS解决方案没有运气。

2 个答案:

答案 0 :(得分:0)

你走了:

Live Demo

我冒昧地将cursor: pointer添加到按钮上。如果您将它们从<img>标签更改为<a>标签,那么从语义角度来看会更好。

我还在size="4"标记中添加了<select>,以确保不同浏览器之间的一致高度。

我没碰到JS。

在IE7 / 8,Firefox,Chrome,Opera,Safari中测试。

<强> CSS:

#container {
    overflow: auto;
    background: #ccc
}
.buttons {
    float: left;
    width: 30px;
    padding: 0 3px
}
.buttons img {
    cursor: pointer
}
.dropdown {
    float: left;
    width: 160px
}

<强> HTML:

<div id="container">
    <div class="buttons">
        <img src="http://www.jgrmx.com/cgr/tiles/generic/images/icons/arrow-up.gif" id="up_button"><br>
        <img src="http://www.jgrmx.com/cgr/tiles/generic/images/icons/arrow-down.gif" id="down_button">
    </div>

    <div class="dropdown">
        <select multiple=true id="left" size="4">
        <option>Patricia J. Yazzie</option>
        <option>Michael A. Thompson</option>
        </select>
    </div>

    <div class="buttons">
        <img src="http://www.jgrmx.com/cgr/tiles/generic/images/icons/arrow-left.gif" id="add_button"><br>
        <img src="http://www.jgrmx.com/cgr/tiles/generic/images/icons/arrow-right.gif" id="remove_button">
    </div>

    <div class="dropdown">
        <select multiple=true id="right" size="4">
        <option>Kevin C. Bounds</option>
        <option>Patricia J. Yazzie</option>
        <option>Michael A. Thompson</option>
        <option>Mark D. Mercer</option>
        </select>
    </div>
</div>

答案 1 :(得分:0)

注意:不跨浏览器友好 - JSFiddle

<style type="text/css">
    .form-wrap div {
        display: inline-block;
        float: left; // makes it work in IE, but breaks it in Firefox
        vertical-align: middle;
    }
    .form-wrap img { display: block; }
</style>

<div class="form-wrap">
    <div class="buttons-left">
        <img src="http://www.jgrmx.com/cgr/tiles/generic/images/icons/arrow-up.gif" id="up_button">
        <img src="http://www.jgrmx.com/cgr/tiles/generic/images/icons/arrow-down.gif" id="down_button">
    </div>

    <div class="select-left">
        <select multiple=true id="left">
            <option>Patricia J. Yazzie</option>
            <option>Michael A. Thompson</option>
        </select>
    </div>

    <div class="buttons-mid">
        <img src="http://www.jgrmx.com/cgr/tiles/generic/images/icons/arrow-left.gif" id="add_button">
        <img src="http://www.jgrmx.com/cgr/tiles/generic/images/icons/arrow-right.gif" id="remove_button">
    </div>

    <div class="select-right">
        <select multiple=true id="right">
            <option>Kevin C. Bounds</option>
            <option>Patricia J. Yazzie</option>
            <option>Michael A. Thompson</option>
            <option>Mark D. Mercer</option>
        </select>
    </div>
</div>