如何为占位符、文本框和按钮应用自定义字体族?

huangapple go评论66阅读模式
英文:

How do you apply a custom font family for placeholder, textbox & button?

问题

我想在占位符和按钮中使用我电脑上的自定义字体。

我的 @font-face。

@font-face {
    font-family: customfont2;
    src: url(Font/otf/segment14.regular.otf);
}

我正在做一个十进制/二进制/十六进制转换器。

<div id="decimal">
    <input placeholder="在此输入十进制">
    <button>转换为十进制</button>
</div>
英文:

I want to use a custom font from my computer for placeholder and button.

My @font-face.

@font-face {
        font-family: customfont2;
        src: url(Font/otf/segment14.regular.otf);
        }

I was doing a Dec/Bin/Hex converter

 &lt;div id=&quot;decimal&quot;&gt;
 &lt;input placeholder=&quot;Type Decimal Here&quot;&gt;
 &lt;button&gt;Convert Decimal&lt;/button&gt;
 &lt;/div&gt;

答案1

得分: 0

For button, you just need something like:

button{ 
    font-family: customfont2;
}

For placeholders, you can try the selectors below:

::-webkit-input-placeholder { /* Edge */
  font-family: customfont2;
}

:-ms-input-placeholder { /* Internet Explorer 10-11 */
  font-family: customfont2;
}

::placeholder {
  font-family: customfont2;
}

更多关于 ::placeholder 选择器的信息

英文:

For button, you just need something like:

button{ 
    font-family: customfont2;
}

For placeholders, you can try the selectors below:

::-webkit-input-placeholder { /* Edge */
  font-family: customfont2;
}

:-ms-input-placeholder { /* Internet Explorer 10-11 */
  font-family: customfont2;
}

::placeholder {
  font-family: customfont2;
}

More about the ::placeholder selector

答案2

得分: 0

使用 input::placeholder

伪元素来样式化输入元素的占位符

@font-face {
    font-family: 'mycustomfont';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url(https://fonts.gstatic.com/s/poppins/v20/pxiEyp8kv8JHgFVrJJbecmNE.woff2);
}

input, button {
    font-family: 'mycustomfont';
}

input::placeholder {
    font-family: 'mycustomfont';
    color: green;
}
<div id="decimal">
    <input placeholder="输入十进制数">
    <button>转换为十进制</button>
</div>
英文:

use input::placeholder

pseudo element to style placeholder of input element

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

@font-face {
    font-family: &#39;mycustomfont&#39;;
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url(https://fonts.gstatic.com/s/poppins/v20/pxiEyp8kv8JHgFVrJJbecmNE.woff2);
}
 
input,button{
  font-family:&#39;mycustomfont&#39;;
}
input::placeholder{
  font-family:&#39;mycustomfont&#39;;
  color:green;
}

<!-- language: lang-html -->

&lt;div id=&quot;decimal&quot;&gt;
 &lt;input placeholder=&quot;Type Decimal Here&quot;&gt;
 &lt;button&gt;Convert Decimal&lt;/button&gt;
&lt;/div&gt;

<!-- end snippet -->

答案3

得分: 0

谢谢各位,但我自己已经搞定了

input[type="text"] {
    font-family: customfont4;
    background-color: rgb(0, 0, 0);
    color: rgb(255, 0, 0);
}

input[type="button"] {
    font-family: customfont3;
}

button {
    font-family: customfont3;
    height: 28px;
    font-size: 12pt;
}

::placeholder {
    font-family: customfont2;
    color: rgb(255, 0, 0);
}
英文:

Thanks guys, but I figured on my own

input[type=&quot;text&quot;]
		{
		font-family: customfont4;
        background-color: rgb(0, 0, 0);
        color: rgb(255, 0, 0);
		}
input[type=&quot;button&quot;]
		{
		font-family: customfont3;
		}
		
button {
font-family: customfont3;
height:28px;
font-size:12pt;
}
::placeholder {
  font-family: customfont2;
    color: rgb(255, 0, 0);
  {

huangapple
  • 本文由 发表于 2023年5月15日 12:59:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76250973.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定