简体   繁体   English

Box Shadow在输入焦点上无法正常工作

[英]Box Shadow works incorrectly on focus in input

<div class="group">
        <input placeholder="Номер карты" class="inpts inpt-card">
        <input placeholder="Владелец карты" class="inpts inpt-owner">
        <input placeholder="ММ/ГГ" class="inpt-mm small-inpts mmgg">
        <input placeholder="CVC" class="inpt-cvc small-inpts cvc">
        <div class="clear"></div>

All code at - https://jsfiddle.net/romariokbn/pspb5urc/ 所有代码-https: //jsfiddle.net/romariokbn/pspb5urc/

I want box-shadow on all of the focused inpts, but some sides of them is under the other inpts. 我希望所有聚焦的inpt都具有阴影效果,但是它们的某些侧面在其他inpts之下。 Z-index changes doesnt work. Z索引更改无效。 How can I do it? 我该怎么做?

You can also just add the css property like shown below 您也可以只添加css属性,如下所示

position: relative; 职位:相对

EDIT: no jquery / js code needed imo 编辑:不需要jQuery / js代码imo

.inpts:focus, .small-inpts:focus { 
    -webkit-box-shadow: 0px 0px 10px 0px #fbb040;
    -moz-box-shadow: 0px 0px 10px 0px #fbb040;
    box-shadow: 0px 0px 10px 0px #fbb040;
    z-index: 10;
    -webkit-appearance: none;
    position: relative;
}

If you really wish to affect all inputs on this page add it within "input" 如果您确实希望影响此页面上的所有输入,请在“输入”中添加它

input {
    outline: none;
    position: relative;
}

Updated jsfiddle 更新了jsfiddle

You could use jQuery to change the z-index property of the input you focus on, then revert the z-index value when you focus out: 您可以使用jQuery更改您关注的输入的z-index属性,然后在关注时还原z-index值:

$("input").on("focusin", function(){
    $(this).css("z-index", 1);
});
$("input").on("focusout", function(){
    $(this).css("z-index", 0);
});

You'll also need to add the following CSS to the input elements for the z-index rule to apply: 您还需要将以下CSS添加到输入元素中,以应用z-index规则:

input {
    outline: none;
    position: relative;
    top: 0; left: 0;
}

EDIT: updated jsfiddle https://jsfiddle.net/pspb5urc/1/ 编辑:更新了jsfiddle https://jsfiddle.net/pspb5urc/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM