简体   繁体   English

如何使用CSS创建多选框,但标签显示在顶部而不是左侧?

[英]How can I use CSS to make a multi-select box but have the label appear on top instead of to the left?

I have a Rails 3.2.8 application and I'm trying to customize some of the classes that come with the simple_form_for gem. 我有一个Rails 3.2.8应用程序,并且我试图自定义simple_form_for gem附带的一些类。

I have a page with many multiple select boxes on it, and to use space wisely I want the labels to appear on top of the select boxes. 我的页面上有很多选择框,为了明智地使用空间,我希望标签出现在选择框的顶部。

I can't quite figure out how to do that. 我不太清楚该怎么做。 I have very little CSS experience and I'm trying to dive right in. I have used float with some success, but when you use simple_form_for you end up with a bunch of nested <div> tag for a form element. 我几乎没有CSS经验,我想尝试一下。我使用float取得了一些成功,但是当您使用simple_form_for时,最终会为表单元素添加一堆嵌套的<div>标记。 So my select box is only floating as far left as the containing <div> tag. 因此,我的选择框仅在包含<div>标记的最左侧浮动。 I want it to be in line with the label. 我希望它与标签一致。 Here is a rendered example: 这是一个渲染的示例:

<div id="attribute_value_list" class="attribute_value_list">
  <div class="control-group select required">
    <label class="select required control-label" for="app_attribute1">
      <abbr title="required">*</abbr>
      Vehicle: Make
    </label>
    <div class="controls">
      <select id="app_attribute1" class="select required select_attribute_value" size="10" name="app[attribute1]">
        ...
      </select>
    </div>
  </div>
</div>

您将需要相对于包含的div应用position:相对于包含div的位置(选择一个包含标签和控件的位置),然后将position:absolute应用于标签,连同左和顶部一起将其放置在所需的位置-相对于包含的div 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM