Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've been looking for the same styling technique for a while. From a UI/UX standpoint - simplifying search forms to a single element makes a lot of sense in certain situations.</p> <p><em>Consider the example below:</em></p> <p><img src="https://i.stack.imgur.com/ninRd.png" alt="Search Form Example"></p> <p>When you approach it from a development standpoint the knee-jerk is to decide to style the form itself instead of the input elements. A transparent input[type=text] to the left, and a transparent .PNG submit button to the right and you've got a sharp looking search field.</p> <p>As you've discovered though, you give up the CSS style capabilities associated with :focus because the input field isn't the one controlling the background / color etc - the form element is instead.</p> <p>The form:focus selector would be a perfect way to handle that. Unfortunately, we've got to wait to CSS4 for that (thanks to matt3141 for the tid-bit).</p> <p>In the meantime, you have a few options available</p> <hr> <h2>Option 1 - Forgo the Clickable Submit Button</h2> <p>I usually try and avoid this if possible, but you have the option to forgo the submit button altogether. Style the text field as you intended, and use a background image with the position limited to the left or of the field right. When the user types in their query, and presses enter, you can still fire a GET action. The example image above uses this technique.</p> <p><em>Example: <a href="http://designdisease.com/" rel="nofollow noreferrer">http://designdisease.com/</a></em></p> <p>Pros: Easiest to set up.</p> <p>Drawbacks: Users who still click search buttons might be confused.</p> <hr> <h2>Option 2 - Use an Alternate Element to Style the Background</h2> <p>Your next option is to take advantage of the sibling selector and content tags as o.v. has so generously explained in his/her previous answer. This in effects adds a new element and styles it to act as a new background for a specified area when the :focus effect is applied to an input field.</p> <p><em>Example: <a href="http://jsfiddle.net/ovfiddle/PEK7h/2/" rel="nofollow noreferrer">http://jsfiddle.net/ovfiddle/PEK7h/2/</a></em></p> <p>Pros: Extendable to larger forms with multiple fields more easily.</p> <p>Drawbacks: The intensive selectors may not degrade as gracefully as we'd like.</p> <hr> <h2>Option 3 - Use Absolute Positioning to Stack the Elements</h2> <p>In situations where the text field will encompass the full width of the form, you can use a the position:absolute; attribute to simply load the submit button over top of the input element, and then a few css tweaks on the button to remove the background / border - giving the same effect as our example image above, but with added benefit of making it clickable.</p> <p><strong>Step One:</strong> Give the form a position - relative/absolute/fixed. </p> <p><strong>Step Two:</strong> Give the text field a width of 100%.</p> <p><strong>Step Three:</strong> Give the button an absolute position, and right position of 0.</p> <p>I've updated o.v.'s fiddle to incorporate the new technique:</p> <p><em>Example: <a href="http://jsfiddle.net/PEK7h/17/" rel="nofollow noreferrer">http://jsfiddle.net/PEK7h/17/</a></em></p> <p>Pro's: Degrades gracefully, gives us what we want in most single input field cases.</p> <p>Drawbacks: Not as easily extendable to large forms like o.v.'s fix is.</p> <p>--</p> <p>As you can see, each option has its own drawbacks - but if you know about them ahead of you can usually lessen their impact. Hope this helps!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload