Unicode Glyph for Padlock

筅森魡賤 提交于 2019-12-06 11:22:28

You should be able to use the glyphicon that ship with bootstrap for free. Also check out Fontawesome

If you decide to use Fontawesome, the unicode character is f023. Or if you include the CSS files you can add the fa-lock class to an <i> tag.

<button type="button"><i class="fa fa-lock"></i></button>

Alternatively, you could specify the font-family in your CSS file after including and importing the fonts into your CSS file.

For instance:

 .your-element:before {
     font-family: "FontAwesome";
     content: "\f023";
 }

You get the idea.

Searching for a Unicode character is off-topic at SO, and so is searching for a “Unicode glyph”, whatever that might mean.

Interpreting the question as asking for a way to include a padlock symbol in an HTML document, there is a simple answer: If there is a Unicode character that corresponds to what you want, use it if this turns out to be feasible enough; if not, use an image, created in sufficiently large size and scaled down to the font size used with CSS. The feasibility depends mainly on fonts. For general information, see my Guide to using special characters in HTML.

In this case, assuming that your search for a suitable Unicode character finds LOCK U+1F512 suitable in principle, you would in practice need to use a downloadable font via @font-face. The only fonts that support it, among fonts normally installed on people’s computers, are Segoe UI fonts, which are available on fairly new versions of Windows only. However, you can put those fonts first in your font-family list, to avoid downloading a font when it is not needed.

(If you would prefer OPEN LOCK U+1F513, for some reason, even though it suggests “open” rather than “locked”, the situation is the same: fonts that support one of these characters support the other as well.)

Example (uses the Symbola font as converted with Fontie; FontSquirrel refused to convert, appearently because Symbola is over 2 megabytes):

<style>
@font-face {
    font-family:'Symbola-Regular';
    src: url('../Fonts/Symbola/Symbola_gdi.eot');
    src: url('../Fonts/Symbola/Symbola_gdi.eot?#iefix') format('embedded-opentype'),
        url('../Fonts/Symbola/Symbola_gdi.woff') format('woff'),
        url('../Fonts/Symbola/Symbola_gdi.ttf') format('truetype'),
        url('../Fonts/Symbola/Symbola_gdi.svg#Symbola-Regular') format('svg');
}
@font-face {
  font-family: Symbola-Regular;
}
.lock { font-family: Segoe UI Symbol, Symbola-Regular; }
</style>
<span class=lock>&#x1f512;</span>

However, this might be overkill when you just want one icon. It is simpler to use just an image, perhaps starting from a LOCK glyph in a free font in large size, taking a screen capture, and then using just an img element:

<img src=lock.png alt=Locked style="height: 0.8em">

You can do this with an embedded vector image that scales just like a font:

This is text is
<svg width=".7em" height=".9em">
  <g transform="translate(-267 -10)">
    <path d="M274.675 14.847v-1.305c0-1.443-1.223-2.61-2.735-2.61-1.512
             0-2.736 1.167-2.736 2.61v1.305h-.684c-.753 0-1.367.587-1.367
             1.306v3.917c0 .72.614 1.305 1.367 1.305h6.84c.758 0 1.367-.586
             1.367-1.305v-3.917c0-.72-.61-1.306-1.368-1.306h-.685zm-1.367
             0h-2.736v-1.305c0-.72.615-1.306 1.368-1.306.753 0 1.368.587
             1.368 1.306v1.305zm-.406
             5.223h-1.92l.386-1.775c-.368-.194-.625-.566-.625-1
             0-.632.54-1.142 1.197-1.142.662 0 1.197.51 1.197 1.142 0
             .434-.257.806-.625 1l.39 1.775z"/>
  </g></svg>
secure.

(Note, I cheated; to make it smaller, I removed the xmlns attribute and a few other elements that, to my untrained SVG eye, appear to be unnecessary.)

You can also embed it as an image with the data: URI scheme:

This is text is
<img style="height:.9em" src="data:image/png;base64,iVBORw0KGgoAAAAN
  SUhEUgAAAB4AAAAkCAMAAACpD3pbAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHO
  kAAABCUExURUxpcQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALENANYAAAAVdFJOUwDTG920xATupruZgE
  v4JA9vO8yLYHMll0gAAADKSURBVDjLvZPbAoMgCIZn5AHtYKve/1UnuIOa3G37b6K+
  +BGo2+1PWoIGwDB0odnnkzWHHsXzLWcu2DMA4MslfyFnXFKgyb+tH9JDzZ5GpTA2mC
  pvOZyoeoMpZX3WISMZD1/Fk0O01FcWdWYR3VQOpKP91Ycgyncy9gmPn1t7DEO0xWoq
  PPPYNgmP+ahawD5jJ2CVvwsQMDdqvFSbV1qOocVrnriAuTiI2NcHb/FBONa4eBvuSV
  C7RXkl5Ga0RDGPKSjbkYrmx7/8A5owKWwwRuJTAAAAAElFTkSuQmCC"/>
secure.

Finally, as noted in another answer, you can use the official Unicode lock character:

This text is &#x1f512; secure

If any font installed on the client's system has this character, it will be rendered, so you only need to specify a font above if you're worried about the client not having this character anywhere. In that case, consider Jukka's answer. Still, I prefer the SVG or PNG methods to actually loading a new font, especially one as big as Symbola's 2.1MB (versus 673B for the SVG or 668B for base64 PNG).

Here is how those all look side by side (SVG, PNG, Unicode), with Firefox on top and Chrome on the bottom (note, I run Linux):

(Note, I don't have a font that renders this character.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!