加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 插入一个css类以在Rails date_select上选择

发布时间:2020-12-17 04:22:43 所属栏目:百科 来源:网络整理
导读:我使用date_select方法生成3个html选择,日,月和年. 但我需要每个选择都有一类CSS. 我没有在文档中找到如何将参数传递给帮助器,我尝试了几种方法,没有. Rails查看: %= f.date_select :birthday,:order = [:day,:month,:year],:start_year = 1910,:end_year =
我使用date_select方法生成3个html选择,日,月和年.
但我需要每个选择都有一类CSS.

我没有在文档中找到如何将参数传递给帮助器,我尝试了几种方法,没有.

Rails查看:

<%= f.date_select :birthday,:order => [:day,:month,:year],:start_year => 1910,:end_year => 2012,:html => {:class => ['day','month','year']} %>

HTML输出:

<select id="poll_user_birthday_3i" name="poll_user[birthday(3i)]">
<select id="poll_user_birthday_2i" name="poll_user[birthday(2i)]">
<select id="poll_user_birthday_1i" name="poll_user[birthday(1i)]">

像我这样的HTML输出:

<select id="poll_user_birthday_3i" name="poll_user[birthday(3i)]" class="day">
<select id="poll_user_birthday_2i" name="poll_user[birthday(2i)]" class="month">
<select id="poll_user_birthday_1i" name="poll_user[birthday(1i)]" class="year">

谢谢!

解决方法

他们解决这个问题的方式是用css

视图

<span class="datetime"> <%= f.date_select :birthdate,:end_year => 2012 %></span>

CSS

.datetime select:nth-child(1){
  width: 130px;
  text-indent: 15px; 
}

.datetime select:nth-child(2) {
  width: 200px;
  text-indent: 5px;
}

.datetime select:nth-child(3) {
  width: 110px;
  text-indent: 15px;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读