CSS 浮动 Div's &结盟
我正在尝试创建一个控件,其中包含两个带有添加/删除按钮的列表框,用于将项目从一个列表移动到另一个列表。通常我会使用表格来完成此操作,但我尝试遵循 css 标准并使用 div。
我的列表框完美对齐,但我不知道如何设置它们之间的按钮。
这是我的 html(已更新以显示渲染的 html):
<div id="dealsummary-ladderlist">
<form action="/Reporting/DealSummaryComparison" method="post">
<div id="available">
<div><strong>Available</strong></div>
<div id="available-items">
<select id="ItemsToSelect" multiple="multiple" name="ItemsToSelect" size="30">
<option value="16">Item 1</option>
<option value="17">Item 2</option>
<option value="21">Item 3</option>
<option value="22">Item 4</option>
<option value="23">Item 5</option>
<option value="24">Item 6</option>
<option value="25">Item 7</option>
</select>
</div>
</div>
<div id="add-remove">
<div><input type="button" value=">>" /></div>
<div><input type="button" value="<<" /></div>
</div>
<div id="selected">
<div><strong>Selected</strong></div>
<div id="selected-items">
<select id="ItemsToDeselect" multiple="multiple" name="ItemsToDeselect" size="30"></select>
</div>
</div>
<div style="clear:both;"></div>
<br /><br />
<center>
<p>
<input type="submit" value="Generate Report" />
</p>
</center>
</form>
</div>
这就是我的 css:
#add-remove {
/* want to center on page */
float: left;
width: 10%;
}
#add-remove div {
/* want to add even spacing between buttons */
}
#available {
float: left;
width: 45%;
}
#selected {
float: right;
width: 45%;
}
#available #available-items,
#selected #selected-items {
margin: 1em 0 0 0;
}
#available #available-items select,
#selected #selected-items select {
width: 100%;
font-size: 10pt;
}
如何使用 css 实现箭头按钮的居中和均匀间距?
I am trying to create a control which contains two listboxes with add/remove buttons to move items from one list to the other. Typically I would do this using a table, but I am trying to follow css standards and use divs.
I have the listboxes aligned perfectly, but I can't figure out how to set up the buttons between them.
This is my html (updated to show rendered html):
<div id="dealsummary-ladderlist">
<form action="/Reporting/DealSummaryComparison" method="post">
<div id="available">
<div><strong>Available</strong></div>
<div id="available-items">
<select id="ItemsToSelect" multiple="multiple" name="ItemsToSelect" size="30">
<option value="16">Item 1</option>
<option value="17">Item 2</option>
<option value="21">Item 3</option>
<option value="22">Item 4</option>
<option value="23">Item 5</option>
<option value="24">Item 6</option>
<option value="25">Item 7</option>
</select>
</div>
</div>
<div id="add-remove">
<div><input type="button" value=">>" /></div>
<div><input type="button" value="<<" /></div>
</div>
<div id="selected">
<div><strong>Selected</strong></div>
<div id="selected-items">
<select id="ItemsToDeselect" multiple="multiple" name="ItemsToDeselect" size="30"></select>
</div>
</div>
<div style="clear:both;"></div>
<br /><br />
<center>
<p>
<input type="submit" value="Generate Report" />
</p>
</center>
</form>
</div>
This is what I have for css:
#add-remove {
/* want to center on page */
float: left;
width: 10%;
}
#add-remove div {
/* want to add even spacing between buttons */
}
#available {
float: left;
width: 45%;
}
#selected {
float: right;
width: 45%;
}
#available #available-items,
#selected #selected-items {
margin: 1em 0 0 0;
}
#available #available-items select,
#selected #selected-items select {
width: 100%;
font-size: 10pt;
}
How would I achieve the centering and even spacing of the arrow buttons using css?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您知道
元素的精确宽度和高度,则可以将整个元素包装在相对定位的
使用 CSS:
将
top
和left
设置为50%
和margin-left
的值的一半width
和margin-top
为height
值的一半将使绝对定位元素在其相对父元素中水平和垂直居中。垂直居中很难实现;您可以使用
display: inline-block; Vertical-align: middle;
,但并非所有浏览器都支持inline-block
。或者,使用display: table-cell; Vertical-align: middle;
往往会起作用。顺便说一句,
元素已被弃用。使用
或简单地使用
代替。
If you know the precise width and height of the
<div id="add-remove">
element, you could wrap the whole thing in a relatively-positioned<div>
and use absolute positioning with negative margins like so:With the CSS:
Setting both
top
andleft
to50%
andmargin-left
to half the value ofwidth
andmargin-top
to half the value ofheight
will horizontally and vertically center an absolutely-positioned element within its relative parent.Vertical-centering is difficult to achieve; you can use
display: inline-block; vertical-align: middle;
, butinline-block
is not supported by all browsers. Alternatively, usingdisplay: table-cell; vertical-align: middle;
tends to work.Incidentally, the
<center>
element is deprecated. Use<div style="text-align: center;">
or simply<p style="text-align: center;">
instead.