I am looking to wrap my text fields and other form elements in a label tag:
<label for="response">Tell me what you think: <input type="text" id="response" name="response"/></label>
This allows me to apply CSS like the following:
label {
white-space: nowrap;
}
Ensuring that the label and form element stay together without breaking onto separate lines. While I could wrap the whole label and form element with a <span>
and use white-space: nowrap;
, I prefer having a single label that encompasses everything. At least in some cases.
My question is, how can I achieve this in Rails using the label_tag
form helper? Should I simply include the other form element within the label_tag call?
<%= label_tag 'response', "Tell me what you think: #{text_field_tag 'response', @prev_response, placeholder: 'Enter response', class: 'specific'}" %>