【问题标题】:add soft glow on focus to input [duplicate]在焦点上添加柔和的光晕到输入[重复]
【发布时间】:2020-04-17 12:57:29
【问题描述】:

我想在输入标签上重新创建这种“聚焦蓝色发光”效果,如下所示:

这是我的努力:

input:focus{
    outline-color : lightskyblue;
    outline-width : 5px;
    border : 1px solid blue;
}
input{
  padding : 0;
  line-height : 35px;
  border-radius : 5px;
  border : 1px solid black;
  width : 500px;
  }
<input type="text" />

但轮廓非常小,不易察觉。而且轮廓也没有圆角。
那么如何重现效果呢?

【问题讨论】:

  • P.S 我不想要任何图书馆。零依赖

标签: javascript html css


【解决方案1】:

你好这里我开发了一个例子,希望对你有用。

*, ::after, ::before {
    box-sizing: border-box;
}

input {
    margin: 0;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
}

input {
    overflow: visible;
}

.input-focus {
    display: block;
    width: 100%;
    height: calc(1.5em + .75rem + 2px);
    padding: .375rem .75rem;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: #495057;
    background-color: #fff;
    background-clip: padding-box;
    border: 1px solid #ced4da;
    border-radius: .25rem;
    transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}

@media (prefers-reduced-motion: reduce) {
    .input-focus {
        transition: none;
    }
}

.input-focus::-ms-expand {
    background-color: transparent;
    border: 0;
}

.input-focus:-moz-focusring {
    color: transparent;
    text-shadow: 0 0 0 #495057;
}

.input-focus:focus {
    color: #495057;
    background-color: #fff;
    border-color: #80bdff;
    outline: 0;
    box-shadow: 0 0 0 .2rem rgba(0, 123, 255, .25);
}

.input-focus::-webkit-input-placeholder {
    color: #6c757d;
    opacity: 1;
}

.input-focus::-moz-placeholder {
    color: #6c757d;
    opacity: 1;
}

.input-focus:-ms-input-placeholder {
    color: #6c757d;
    opacity: 1;
}

.input-focus::-ms-input-placeholder {
    color: #6c757d;
    opacity: 1;
}

.input-focus::placeholder {
    color: #6c757d;
    opacity: 1;
}

.input-focus:disabled {
    background-color: #e9ecef;
    opacity: 1;
}

@media print {
    *, ::after, ::before {
        text-shadow: none !important;
        box-shadow: none !important;
    }
}
<input type="text" class="input-focus" aria-describedby="emailHelp">

【讨论】:

    【解决方案2】:

    您可以尝试在 CSS 中使用 box shadowRGBA 以对边框的发光 产生略微透明的效果。这应该会为您提供所需的 柔和发光 效果,因为其中的模糊和一点点透明度,例如:

    input:focus {
      outline-color: lightskyblue;
      outline-width: 1em;
      border: .25em solid blue;
      box-shadow: 0em 0em .75em rgba(0,0,255,0.95);
    }
    
    input {
      padding: 0;
      line-height: 35px;
      border-radius: 5px;
      border: 1px solid black;
      width: 500px;
    }
    <input type="text" />

    使用盒子阴影,您可以设置:v-offset h-offset 模糊。第三个设置是让您在边界/轮廓周围看到模糊或模糊的外观。有关更多详细信息,请查看MDN

    【讨论】:

      【解决方案3】:

      .input{
      	padding : 0;
        	line-height : 35px;
        	border-radius : 5px;
              border : 1px solid black;
              width : 500px;
      }
      
      input:focus{
          outline: none !important;
          border:1px solid red;
          box-shadow: 0 0 10px #719ECE;
      }
      <input class="input" />

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-08
        • 2019-11-27
        • 1970-01-01
        • 2013-08-26
        • 2017-01-24
        相关资源
        最近更新 更多