【问题标题】:Width of position:absolute input tag not correct on iPad位置宽度:iPad 上的绝对输入标签不正确
【发布时间】:2025-12-02 01:15:02
【问题描述】:

我正在尝试将输入元素放置在带有背景的 div 中,我需要对它进行绝对大小和定位。它在 PC 上运行正常,但如果不使用完全不同的值,我无法在 iPad 上正确运行。

PC 上的外观

在 iPad 上的外观

HTML:

<div id="container">
    <input class="input-pc" type="text"/>
</div>
<br/>
<div id="container">
    <input class="input-ipad" type="text"/>
</div>

CSS:

#container{
    background-color: #343434;
    position: relative;
    width: 200px;
    height: 26px;
}

.input-pc {
    position: absolute;
    left: 2px;
    top: 2px;
    width: 196px;
    height: 20px;
    background-color: #E8FB46;
    border: none;
}

.input-ipad {
    -webkit-appearance: none;
    -webkit-border-radius:0;
    position: absolute;
    left: 2px;
    top: 2px;
    width: 186px;
    height: 17px;
    background-color: #E8FB46;
    border: none;
}

Here is a fiddle 有两种适用于 PC 和 iPad 的样式。

有没有办法让两个输入字段正确包含在两个平台上?

【问题讨论】:

    标签: html css ipad


    【解决方案1】:

    我没有对此进行测试,但我想这应该适用于两种设备,因为我没有使用任何相对/绝对定位。相反,我只使用简单的 CSS。这是html:

    <div id="newContainer">
        <input class="input" type="text"/>
    </div>
    

    这是 CSS:

    * {
        margin:0;
        padding:0;
    }
    
    div {
        margin:20px 0 0 20px;
    }
    #newContainer{
        background-color: #343434;
        width: 200px;
        height: 23px;
        padding:1px 2px 0px 2px;
        border:0;
    }
    
    .input {
        width: 100%;
        height: 20px;
        background-color: #E8FB46;
        border: none;
    }
    

    你可以在这里看到这个:http://jsfiddle.net/6mVHJ/2/

    希望对你有帮助!!!

    【讨论】:

    • 不幸的是,这并不能解决问题。在 iPad 上,黄色输入框延伸到 div 的右侧......当我尝试这个时,我已经更新了我的小提琴以使用填充代替。 Updated JSFiddle