Search code examples
ruby-on-railsruby-on-rails-3csssimple-form

Make help message appear below form field with Rails/devise/boostrap/simple_form


On https://login.mailchimp.com/signup, when you click on a form (:focus), a "help message" appears below. For example "what's your email address?" appears below email.

I tried to analyze their css but I failed to apply such a thing on my code. I think I'm missing something important, like how to tell the program that I want it to appear when the user clicks inside the field.

Here is my code

Rails view:

<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {:class => 'form-vertical' }) do |f| %>
  <fieldset>
    <%= f.error_notification %>
    <%= display_base_errors resource %>
    <%= f.input :email,                                 :required => true, placeholder: t("devise.registrations.sign_up_page.whats_your_email_address") %>
    <div class="field-help"> What's your email address? </div>
    <%= f.input :password,                          :required => true %>
    <%= f.input :password_confirmation, :required => true %>

    <div class="fullsized"><%= f.button     :submit, t("devise.registrations.sign_up_page.sign_up"), :class => 'btn-primary' %>
    </div>
  </fieldset>
<% end %>

css:

.field-help {
-webkit-transition: all 0.25s ease-in-out 0s;
-moz-transition: all 0.25s ease-in-out 0s;
-o-transition: all 0.25s ease-in-out 0s;
-ms-transition: all 0.25s ease-in-out 0s;
transition: all 0.25s ease-in-out 0s;
display: block;
opacity: 0;
max-height: 0;
top: -1.8461538461538463em;
overflow: hidden;
white-space: normal;
width: 100%;
max-width: 550px;
word-wrap: break-word;
font-size: 0.8125em;
line-height: 1.3846153846153846em;
font-weight: 700;
position: relative;
color: #737373;
letter-spacing: .01em

}


Solution

  • You should use CSS3 fade in/out flair. Try add this style :

    fieldset input:focus+.field-help {
        opacity:1;
        top: 0;
        max-height: 20px;
        margin-bottom:10px;
    }
    

    demo : http://jsfiddle.net/RVGPd/1/