我在输入字段上添加了一个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>
答案 0 :(得分:4)
试试这个:
.checkout input:focus {
margin-right: 50px;
padding: 2px;
margin: -1px;
}
因为您在边框上添加了3px并且在未聚焦状态下填充了2px,所以您必须对聚焦状态进行一些计算,使其等于未聚焦的状态。在你的情况下,在聚焦状态下对边缘做-1px应该取消跳转。
答案 1 :(得分:3)
拥有之前没有一个边框(或增加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;
}
答案 2 :(得分:0)
是的,因为输入字段占用的水平空间在获得焦点时增加了6个像素,因为边框仅在焦点期间应用,并且每侧为3px。而是设置边框始终存在并在焦点期间更改border-color属性。