I'm looking to clone the Google Instant "underlay/type ahead" type look, where what the system is predicting is grayed out and infront of what you are typing.
The technical part of it I am completely sorted, as well as representing the text. I simply am unable to work out how to do the CSS positioning and transparent textbox over the top of the gray text.
Anyone know how to simply do this?
I've tried to adapt code from other sources, but been unable to get the text with the gray text underneath a transparent textbox.
Text Opacity CSS You can set the opacity of an entire element — the background, text within the element, the border, and everything else — using the opacity property. To set the opacity of text and only text, then you need to use the CSS color property and RGBA color values.
Setting Transparent Boxes You can set the CSS transparent background for boxes by adding the opacity property to multiple <div> elements. Tip: you should notice that texts inside boxes take the opacity of the CSS transparent background. The RGBA function allows you to keep the text opacity.
I believe you're looking for something like this. Keep in mind they need to be posiitoned together, so it's probably a good idea to wrap this in a div
together.
<div class='top'>
<input type='text' id='gray'/>
</div>
<div>
<input type='text' id='type'/>
</div>
.top {
background:transparent;
position:relative;
}
input {
font-size: 14px;
width: 200px;
}
#type {
background: transparent;
z-index: 1;
}
#gray {
position: absolute;
z-index: -1;
color: silver;
}
http://jsfiddle.net/r4jSR/
Edit
This positioning works by stacking a position:relative
div
on top of another block level element, then setting the div
's contents to absolute, but with no positioning. This causes the div
to collapse as it has no contents, and - as long as neither block element has a margin - the 0,0
coordinates for absolute positioning should put it right on top of the block element below. Presto. This is the way Google does it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With