热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

仅模糊输入内的文本,而不是整个元素-Bluronlytextinsideinput,notwholeelement

ForvariousreasonsIwanttographicallyblur(i.e.notfocusblur)thetextinsideaninputoftyp

For various reasons I want to graphically blur (i.e. not focus/blur) the text inside an input of type=text, not the whole element.

由于各种原因,我想以图形方式模糊(即不聚焦/模糊)text = text的输入内的文本,而不是整个元素。

Is there a way to do this?

有没有办法做到这一点?

I currently have this:

我目前有这个:

.validation:not(:focus) {
    -webkit-filter: blur(3px);
    filter: blur(3px);
    border:0;
}
    
.validation-border{
    border: 1px black solid;
    z-index:20;
}

The last class style definition is to replace the border of the input with of class validation.

最后一个类样式定义是用类验证替换输入的边框。

But this is far from perfect:

但这远非完美:

  1. The border 'perimeter' is not the same dimension
  2. 边界“周长”的尺寸不同

  3. If I increase the size of the outer border, I still get some blur leakage
  4. 如果我增加外边框的大小,我仍然会有一些模糊泄漏

example of mega border and blur leakage

Is there a better way of blurring the text only, and not the bounding box? Or some other way to cover up the side effects of blurring the input element

有没有更好的模糊文本的方法,而不是边界框?或者其他一些方法来掩盖模糊输入元素的副作用

3 个解决方案

#1


6  

Rather than effecting the whole box, just we change the font color to transparent and add a text shadow effect.

我们不是影响整个框,而是将字体颜色更改为透明并添加文本阴影效果。

.blur-on-lose-focus:not(:focus) {
     color: transparent;
     text-shadow: 0 0 5px rgba(0,0,0,0.5);
}

This is detailed here.

这里详细说明。

#2


2  

Unfortunately, you cannot blur the interior of an element (at the time of writing) without also blurring its bounding box, border, etc. An alternative approach would be:

不幸的是,你不能模糊元素的内部(在写作时),也不会模糊其边界框,边框等。另一种方法是:

Where you style the .input-like container to look like an input (border, etc.). Then remove the border and other styles from the contained input element. At that point you can apply the blur filter to the input and leave the containing element unchanged.

将.input-like容器的样式设置为输入(边框等)。然后从包含的input元素中删除边框和其他样式。此时,您可以将模糊滤镜应用于输入并保持包含元素不变。

The blur leakage seems to be coming from the white background of the input—try setting background-color: transparent; on the input and background-color: white; on the containing element.

模糊泄漏似乎来自输入尝试设置背景颜色的白色背景:透明;关于输入和背景颜色:白色;在包含元素上。

Live example.

#3


1  

Remove the input's border entirely (not just when its not focussed)

完全删除输入的边框(不仅仅是当它没有聚焦时)

.validation {
    border:0px;
}

Also, you could remove the focus outline (although this is not recommended for accessibility reasons):

此外,您可以删除焦点轮廓(尽管出于可访问性原因,不建议这样做):

.validation:focus {
    outline:none;
}

.validation{
  border:0px;
}
.validation:not(:focus) {
  -webkit-filter: blur(3px);
  filter: blur(3px);
}
.validation:focus {
  outline:none;
}
.validation-border{
  border: 1px black solid;
}



推荐阅读
  • 抽空写了一个ICON图标的转换程序
    抽空写了一个ICON图标的转换程序,支持png\jpe\bmp格式到ico的转换。具体的程序就在下面,如果看的人多,过两天再把思路写一下。 ... [详细]
  • 标题: ... [详细]
  • 花瓣|目标值_Compose 动画边学边做夏日彩虹
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了Compose动画边学边做-夏日彩虹相关的知识,希望对你有一定的参考价值。引言Comp ... [详细]
  • 正则表达式及其范例
    为什么80%的码农都做不了架构师?一、前言部分控制台输入的字符串,编译成java字符串之后才送进内存,比如控制台打\, ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 本文介绍了C#中数据集DataSet对象的使用及相关方法详解,包括DataSet对象的概述、与数据关系对象的互联、Rows集合和Columns集合的组成,以及DataSet对象常用的方法之一——Merge方法的使用。通过本文的阅读,读者可以了解到DataSet对象在C#中的重要性和使用方法。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 1,关于死锁的理解死锁,我们可以简单的理解为是两个线程同时使用同一资源,两个线程又得不到相应的资源而造成永无相互等待的情况。 2,模拟死锁背景介绍:我们创建一个朋友 ... [详细]
  • 《数据结构》学习笔记3——串匹配算法性能评估
    本文主要讨论串匹配算法的性能评估,包括模式匹配、字符种类数量、算法复杂度等内容。通过借助C++中的头文件和库,可以实现对串的匹配操作。其中蛮力算法的复杂度为O(m*n),通过随机取出长度为m的子串作为模式P,在文本T中进行匹配,统计平均复杂度。对于成功和失败的匹配分别进行测试,分析其平均复杂度。详情请参考相关学习资源。 ... [详细]
  • 本文介绍了在iOS开发中使用UITextField实现字符限制的方法,包括利用代理方法和使用BNTextField-Limit库的实现策略。通过这些方法,开发者可以方便地限制UITextField的字符个数和输入规则。 ... [详细]
  • 本文介绍了Oracle存储过程的基本语法和写法示例,同时还介绍了已命名的系统异常的产生原因。 ... [详细]
  • 用Vue实现的Demo商品管理效果图及实现代码
    本文介绍了一个使用Vue实现的Demo商品管理的效果图及实现代码。 ... [详细]
  • 本文详细介绍了使用C#实现Word模版打印的方案。包括添加COM引用、新建Word操作类、开启Word进程、加载模版文件等步骤。通过该方案可以实现C#对Word文档的打印功能。 ... [详细]
  • 大数据Hadoop生态(20)MapReduce框架原理OutputFormat的开发笔记
    本文介绍了大数据Hadoop生态(20)MapReduce框架原理OutputFormat的开发笔记,包括outputFormat接口实现类、自定义outputFormat步骤和案例。案例中将包含nty的日志输出到nty.log文件,其他日志输出到other.log文件。同时提供了一些相关网址供参考。 ... [详细]
  • 本文介绍了如何在Jquery中通过元素的样式值获取元素,并将其赋值给一个变量。提供了5种解决方案供参考。 ... [详细]
author-avatar
幽雅闲居xl
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有