0

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

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

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

4

2 回答 2

0

Here you go:

Live Demo

I took the liberty of adding cursor: pointer to the buttons. It would be better from a semantic point of view if you changed them from <img> tags to <a> tags.

I also added size="4" to the <select> tags to ensure consistent height between different browsers.

I didn't touch the JS.

Tested in 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>
于 2011-01-25T00:39:37.277 回答
0

NOTE: Not cross-browser friendly - 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>
于 2011-01-25T00:41:13.260 回答