代码之家  ›  专栏  ›  技术社区  ›  Jeaf Gilbert

锚定技巧在Firefox中不起作用

  •  0
  • Jeaf Gilbert  · 技术社区  · 14 年前

    这段代码在Firefox和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

    注:div的宽度必须为50%。

    谢谢:)

    4 回复  |  直到 14 年前
        1
  •  0
  •   Knio    14 年前
    <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> 在某些浏览器中表现不好,请将其包装在div中

        2
  •  2
  •   Kevin    14 年前

    left:0;

    <div style="border:1px solid red; width:50%; height:50px; position:relative;">
        <input type="text" style="position:absolute; right:20px;" />
    </div>
    
        3
  •  0
  •   Stephan Muller    14 年前
        4
  •  0
  •   Dan Phillimore    13 年前

    在外面用盒子大小的怎么样 <div> ? 这样可以避免添加额外的:

    <div style="border:1px solid red; width:50%; height:50px; position:relative; padding-right:20px; box-sizing:border-box;">
        <input type="text" style="width:100%;" />
    </div>
    

    当然,这只适用于如果你不介意添加填充到外部 <

    在FF 4.0和Chrome 10.0中测试