Foundation 5, Simple Form and Rails - how to get 'hints' CSS class working

坚强是说给别人听的谎言 提交于 2019-12-05 20:45:32

I know the project this question came from is dead now (as reported by @tentimes), but I have this working and have some default styles that may help others in the future.

As both @tentimes and @Thomas_Taylor mentioned, it is important to use the provided generator, like so:

rails generate simple_form:install --foundation

and then to un-comment the following line from config/initializers/simple_form_foundation.rb

b.use :hint,  wrap_with: { tag: :span, class: :hint }

The final step is providing your own CSS (as mentioned in the simple_form documentation). Below is what I used. It uses the info color (#a0d3e8) from the Foundation global styles and has a nice hover effect when the input field with the hint is moused over.

# in framework_and_overrides.css.scss

.simple_form .field_with_hint input{
  margin-bottom: 0;
  &:hover~.hint{
    display: block;
  }
}

.simple_form .hint {
  display: none;
  padding: 0.375rem 0.5625rem;
  margin-bottom: 1rem;
  font-size: 0.75rem;
  font-weight: normal;
  font-style: italic;
  background: #a0d3e8;
  color: white;
}

When you ran the simple form generator did you add --foundation at the end? Documentation (https://github.com/plataformatec/simple_form) reads:

To generate wrappers that are compatible with Zurb Foundation 5, pass the foundation option to the generator, like this:

rails generate simple_form:install --foundation

Did you also do the below:

Please note that the Foundation wrapper does not support the :hint option by default. In order to enable hints, please uncomment the appropriate line in config/initializers/simple_form_foundation.rb. You will need to provide your own CSS styles for hints.

Hope that helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!