V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
gangsta
V2EX  ›  问与答

去掉 Chrome 输入框激活时的蓝色边框

  •  
  •   gangsta · 2014-08-20 10:15:41 +08:00 · 3219 次点击
    这是一个创建于 3554 天前的主题,其中的信息可能已经有所发展或是发生改变。
    Chrome中原生表单输入框或者按钮active时会有一个蓝色的外廓边框,个人觉得比较难看

    http://stackoverflow.com/q/2943548/1299675
    综合上面这个帖子里和Google得到的一些css hack,可以去掉:

    input, input:focus, button, button:focus{
    outline:none;
    outline:1px !important;
    }

    但是这样写CSS样式后,在有的浏览器里会有问题:
    输入框无法获得焦点
    而且也存在原答主说的那个问题:
    but keep in mind this is potentially bad for usability: It will be hard to tell whether an element is focused, which can suck when you walk through all a form's elements using the Tab key - you should reflect somehow when an element is focused.

    ---------------------------------------------

    请问大家都是怎么解决这个问题的?
    2 条回复    2014-08-20 11:29:00 +08:00
    crs0910
        1
    crs0910  
       2014-08-20 11:18:41 +08:00   ❤️ 1
    如果是自己的网站,那就定义focus的样式,去outline然后加个边框或者阴影。
    “无法获得焦点”的情况不知道,没见过去掉outline会这样。
    如果是想改掉chrome的默认样式,那也只能去掉outline了,加其它样式可能跟一些网站的样式不搭,这个没办法。
    gangsta
        2
    gangsta  
    OP
       2014-08-20 11:29:00 +08:00
    @crs0910

    我在iPhone上用Safari测试,输入框获取焦点不行

    参考了下BootStrap的写法 确实是通过:focus的样式来处理的.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5818 人在线   最高记录 6547   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 06:41 · PVG 14:41 · LAX 23:41 · JFK 02:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.