【问题标题】:Form input, when focused, causes submit button to move slightly表单输入,当聚焦时,会导致提交按钮轻微移动
【发布时间】:2013-12-27 19:13:56
【问题描述】:

感谢您的帮助,我敢打赌这很容易解决。

我已将自定义 :focus 应用于我的输入,它删除了默认轮廓(发光)并添加了框阴影和边框。唯一的问题是,当输入字段获得焦点时,由于边框和框阴影,位于输入右侧的提交按钮会向右跳大约一两个像素。很烦人。

JSFiddle:http://jsfiddle.net/D3k3B/

<form action="#" method="get">
            <input type="text" name="email" placeholder="Your email">
            <input type="Submit" name="submit" value="Go">
</form>

form {
    position: absolute;
    bottom: 20%;
    width: 400px;
    left: 50%;
    margin-left: -125px;

}

input[name="email"] {
    font-family: "Prosto One";
    width: 200px;
    height: 25px;
    font-size: 14px;
    background-color: rgba(0,0,0,.4);
    border: none;
    border-radius: 10px;
    color: white;

}

input:focus {
    outline: none;
    border: 1px solid yellow;
    box-shadow: 0px 0px 10px yellow;
}

input[name="submit"] {
    margin: -5px;
    width: 50px;
}

谢谢!

【问题讨论】:

    标签: css forms


    【解决方案1】:

    设置边框 1px 实心透明输入[name="email"]

    input[name="email"] {
        font-family: "Prosto One";
        width: 200px;
        height: 25px;
        font-size: 14px;
        background-color: rgba(0,0,0,.4);
        border: 1px solid transparent;
        border-radius: 10px;
        color: white;
    
    }
    

    【讨论】:

      【解决方案2】:

      您需要将您的边框 css 与一个透明值相匹配,以便它们在应用时不会移动

      input[name="email"] {
          font-family: "Prosto One";
          border: 1px solid transparent;
          width: 200px;
          height: 25px;
          font-size: 14px;
          background-color: rgba(0,0,0,.4);
          border-radius: 10px;
          color: white;
      
      }
      

      工作示例: http://jsfiddle.net/whiteb0x/D3k3B/3/

      【讨论】:

      • 非常感谢,我希望我能自己解决这个问题。呵呵!
      • 有点棘手,我记得前阵子也遇到过
      猜你喜欢
      • 2023-03-30
      • 2014-01-24
      • 1970-01-01
      • 1970-01-01
      • 2017-03-13
      • 2019-03-01
      • 1970-01-01
      • 2017-07-16
      • 1970-01-01
      相关资源
      最近更新 更多