当聚焦于具有3px边框的输入字段时,所有其他输入字段继续移动

Kam*_*Kam 7 html css

我在输入字段上添加了一个css焦点.它具有包含边框和阴影的默认样式.当我专注于输入字段时,下面的输入字段会略微向下移动.我尝试为li增加一个高度,但这不起作用.

   /* CSS


   input[type="text"], 
   input[type="password"] {

   border: 1px solid #CCCCCC;
  box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.2);
  min-height: 22px;
 padding: 3px;

  }

 .checkout input:focus {
 border:3px solid #6b991c; 
 padding:2px;
 }

 */

<ul class="clearFix">
                    <li>                     
                      <label for="title" class="checkoutLabel">Title <strong class="requiredInfo">*</strong></label> 
                      <select name="title" id="title" class="required">
                        <option selected="selected">Please select</option>
                        <option value="Mr">Mr</option>
                        <option value="Mrs">Mrs</option>
                        <option value="Miss">Miss</option>
                        <option value="Dr">Dr</option>
                      </select>
                    </li>
                    <li class="active">
                      <label class="checkoutLabel" for="firstName">First name <strong class="requiredInfo">*</strong></label>
                      <div class="checkoutInputLarge">
                        <input type="text" name="firstName" id="firstName" class="required" />
                      </div>  
                    </li>
                    <li>
                        <label for="lastName" class="checkoutLabel">Last name <strong class="requiredInfo">*</strong> </label>
                        <div class="checkoutInputLarge active">
                            <input type="text" name="lastName" id="lastName" class="checkoutInput1 required" />   
                        </div>
                    </li>

                    <li>
                        <label for="email" class="checkoutLabel">Email <strong class="requiredInfo">*</strong></label> 
                        <div class="checkoutInputLarge">
                            <input type="text" name="email" id="email" class="required" />
                        </div>
                    </li>
                    <li>
                        <label for="phoneNumber" class="checkoutLabel">Phone number <strong class="requiredInfo">*</strong></label> 
                        <div class="checkoutInputLarge">
                            <input type="text" name="phoneNumber" id="phoneNumber" class="checkoutInput1 required" />
                        </div>
                    </li>
                    <li>
                      <input type="checkbox" name="smsAlert" id="smsAlert" /><label for="smsAlert" class="smsAlertLabel">I wish to receive SMS alerts on my order status</label>
                    </li>
                    <li>
                        <label class="checkoutLabel">Are you a <br /> business customer? <strong class="requiredInfo">*</strong></label> 
                        <input type="radio" name="businessCustomer" id="businessCustYes"  value="yes" class="radio required" /><label class="businessCustomerLabels" for="businessCustYes">Yes</label>
                        <input type="radio" name="businessCustomer" id="businessCustNo" value="no" class="radio required" checked="checked" /><label class="businessCustomerLabels" for="businessCustNo">No</label>
                    </li>
                  </ul> 
Run Code Online (Sandbox Code Playgroud)

Jon*_*uis 5

拥有一个之前没有的边框(或增加border-width)将有效地使元素变大,因此可能会导致其他元素移动。为避免这种情况,您应该尝试确保总大小(高度或宽度 + 填充 + 边框 + 边距)相同。在您的情况下,我认为您应该尝试向未聚焦的样式添加 2px 边距以进行补偿(因为聚焦元素的边框大 2px)。尝试:

  input[type="text"], 
  input[type="password"] {
      border: 1px solid #CCCCCC;
      box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.2);
      min-height: 22px;
      padding: 3px;
      margin: 2px;
  }

 .checkout input:focus {
     border:3px solid #6b991c; 
     padding:2px;
     margin: 0;
 }
Run Code Online (Sandbox Code Playgroud)


Sha*_*aoz 5

尝试这个:

.checkout input:focus {
  margin-right: 50px;
  padding: 2px;
  margin: -1px;
}
Run Code Online (Sandbox Code Playgroud)

因为您在边框上添加了3px,在未聚焦状态上添加了2px的填充,所以您必须对聚焦状态进行一些数学运算,以使其等于未聚焦状态。在您的情况下,在聚焦状态下在空白处加上-1px应该会取消跳转。