Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent text box underlay

Tags:

html

css

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.

like image 866
James Avatar asked Sep 21 '10 03:09

James


People also ask

How do I make text opacity?

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.

How do you make a text box transparent in CSS?

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.


1 Answers

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.

HTML

<div class='top'>
    <input type='text' id='gray'/>
</div>
<div>
    <input type='text' id='type'/>
</div>​

CSS

.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;
}​

Live Example

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.

like image 191
Robert Avatar answered Nov 02 '22 17:11

Robert