CSS 焦点最后一个 child

标签 css twitter-bootstrap-3 css-selectors focus

我正在使用在输入后添加标签的验证器,我想更改跨度中的最后一个标签

  <span class="input-icon">                                            
      <input type="text" id="name" name="name" class="form-control" data-fv-field="name">
      <i class="form-control-feedback" data-fv-icon-for="name" style="display: none;"></i>                                                    
      <i class="fa fa-globe blue circular"></i>                                                
  </span>

  .input-icon :last-child  {
      box-shadow : 0 0 0 0.1em rgba(0, 0, 0, 0.1) inset;   
  }

我需要的是访问最后一个 <i>输入焦点 我在下面添加了代码,但没有一个有效

    .input-icon > input:focus + .circular  {
        box-shadow : 0 0 0 0.1em rgba(0, 0, 0, 0.25) inset !important;   
    }

   .input-icon > input:focus .circular  {
        box-shadow : 0 0 0 0.1em rgba(0, 0, 0, 0.25) inset !important;   
    }

   .input-icon > input:focus :last-child  {
        box-shadow : 0 0 0 0.1em rgba(0, 0, 0, 0.25) inset !important;   
    }

   .input-icon > input:focus + [class*="fa-"], .input-icon > input:focus :last-child  {
       opacity: 1;
    }

最佳答案

+ 将以下一个直接同级元素为目标。如果您想找到所有兄弟元素,请使用 ~ 而不是 +

   .input-icon > input:focus ~ .circular  {
    box-shadow : 0 0 0 0.1em rgba(0, 0, 0, 0.25) inset !important;   
    }

    .input-icon > input:focus .circular  {
    box-shadow : 0 0 0 0.1em rgba(0, 0, 0, 0.25) inset !important;   
    }

   .input-icon > input:focus :last-child  {
    box-shadow : 0 0 0 0.1em rgba(0, 0, 0, 0.25) inset !important;   
   }

   .input-icon > input:focus ~ [class*="fa-"], .input-icon > input:focus :last-child  {
   opacity: 1;
   }

DEMO

关于CSS 焦点最后一个 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34019393/

相关文章:

javascript - AngularJS 触发功能单击 anchor 链接

Jquery Mobile可折叠 ListView 对齐文本和按钮

jquery - 如何在表格中设置 child 编号

css - 如何使用伪元素选择指向以 foo 结尾的域的链接?

CSS动画、状态变化完成动画

php - Bootstrap 模态不会显示

css - Bootstrap 3 侧面背景图片

twitter-bootstrap - 如何从外部链接打开选项卡?

html - CSS 隐藏与具有绝对位置的 div 重叠的 div 的内容

css - 为什么 CSS 从一开始就没有设计父选择器?