Get input type=text to look like type=password

后端 未结 7 1868
南笙
南笙 2020-11-29 07:10

tl;dr

I have an input with type=text which I want to show stars like an input with type=password using only CSS.


Basically I

7条回答
  •  -上瘾入骨i
    2020-11-29 07:56

    You can create a font made only of dots

    @font-face
        {
        font-family:'dotsfont';
        src:url('dotsfont.eot');
        src:url('dotsfont.eot?#iefix')  format('embedded-opentype'),
            url('dotsfont.svg#font')    format('svg'),
            url('dotsfont.woff')        format('woff'),
            url('dotsfont.ttf')         format('truetype');
        font-weight:normal;
        font-style:normal;
    }
    
    input.myclass
        {-webkit-text-security:disc;font-family:dotsfont;}
    

    This might be what you're looking for...

    There are many glyphs to define but there might be a simpler way to do that.. You can create a totally empty font and define only the .notdef glyph (glyph ID 0) which is used as a replacement when another glyph is not defined

    As you probably know, it usually looks like this: missing glyph icons

    So, you should replace that with a dot/asterisk and test what happens with browsers... because i'm not sure if it does work on all of them (some may want to use their own missing glyph replacement). Let me know if you try...

    HTH

提交回复
热议问题