[contact form 7] label above Inputs
-
I’m trying to use the script
https://steadicat.github.io/labels/
I’m sitting on this for a long time and I’ve had enough. Please help.
It’s not working corectly with contact form 7.
The reason of the problem is the presence of multiple ‘span’ tag.This is example of my input code:
<div class="row"> <div class="large-12 columns"> <label class="input"><span>Your name</span> [text* your-name class:c_name placeholder ""] </label> </div> </div>
Could I ask someone experienced to help and improve the script?
CSS .input { display: block; } .input span { position: absolute; z-index: 1; cursor: text; pointer-events: none; color: #999; /* Input padding + input border */ padding: 7px; /* Firefox does not respond well to different line heights. Use padding instead. */ line-height: 17px; /* This gives a little gap between the cursor and the label */ margin-left: 2px; } .input input, .input textarea, .input select { z-index: 0; padding: 6px; margin: 0; font: inherit; line-height: 17px; } .input select { padding: 5px; /* Unfortunately selects don't respond well to padding. They need an explicit height. */ height: 31px; } JavaScript /* Copyright (c) 2009 Stefano J. Attardi, https://attardi.org/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ (function($) { function measureWidth(deflt) { var dummy = $('<label></label>').text(deflt).css('visibility','hidden').appendTo(document.body); var result = dummy.width(); dummy.remove(); return result; } function toggleLabel() { var input = $(this); var deflt = input.attr('title'); var span = input.prev('span'); setTimeout(function() { if (!input.val() || (input.val() == deflt)) { span.css('visibility', ''); if (deflt) { span.css('margin-left', measureWidth(deflt) + 2 + 'px'); } } else { span.css('visibility', 'hidden'); } }, 0); }; $(document).on('cut', 'input, textarea', toggleLabel); $(document).on('keydown', 'input, textarea', toggleLabel); $(document).on('paste', 'input, textarea', toggleLabel); $(document).on('change', 'select', toggleLabel); $(document).on('focusin', 'input, textarea', function() { $(this).prev('span').css('color', '#ccc'); }); $(document).on('focusout', 'input, textarea', function() { $(this).prev('span').css('color', '#999'); }); function init() { $('input, textarea, select').each(toggleLabel); }; // Set things up as soon as the DOM is ready. $(init); // Do it again to detect Chrome autofill. $(window).load(function() { setTimeout(init, 0); }); })(jQuery);
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘[contact form 7] label above Inputs’ is closed to new replies.