views:

35

answers:

3

This code has different result in Firefox and Chrome

<div style="border:1px solid red; width:50%; height:50px; position:relative;">
    <input type="text" style="position:absolute; left:0; right:20px;" />
</div>

alt text

How to make the text box anchored 0px to the left and 20px to the right side of the div?

NOTE: div's width must fluid 50%.

Thank you :)

+2  A: 

Get rid of left:0;

<div style="border:1px solid red; width:50%; height:50px; position:relative;">
    <input type="text" style="position:absolute; right:20px;" />
</div>
Kevin
im sorry, i want it anchored 0px to the left as well
Jeaffrey Gilbert
A: 

"How to make the text box anchored 20px to the right side of the div?" Either I don't get what you mean by this, or the example works perfectly fine.

http://jsfiddle.net/GmMCQ/

Litso
what browser did you use? it's not working in firefox.
Jeaffrey Gilbert
A: 
<div style="border:1px solid red; width:50%; height:50px; position:relative;">
    <div style="position:absolute; left:0; right:20px;">
        <input type="text" style="width: 100%" />
    </div>
</div>

<input> behaves badly in some browsers, wrap it in a div

Knio
What in the world are you doing with that extra div!? Remove it now before I shoot you.
Yi Jiang
^ What he said.
Litso
`<input>` doesn't behave the same as a regular block element with both `left:` and `right:` set at the same time in FF, but it does understand `width: 100%`. If you have a better solution, let's see it :)
Knio
Edited: @Knio No no i was wrong it works!
Jeaffrey Gilbert
@Litso Do you have a solution to remove extra div? It will be great :)
Jeaffrey Gilbert
Sorry, no. Tested it and have to agree with Krio, despite the extra div.
Litso