Html 如何更改联系表单上的提交按钮字体

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17643061/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 11:08:48  来源:igfitidea点击:

how to change submit button font on contact form

htmlcsswebforms

提问by milcak

The 7th line from the end I tried to add in some CSS but it won't change the font on the button. Is there a way to do it in CSS or PHP? (Or maybe a way that actually works in HTML)

最后的第 7 行我尝试添加一些 CSS,但它不会更改按钮上的字体。有没有办法在 CSS 或 PHP 中做到这一点?(或者也许是一种在 HTML 中实际有效的方式)

Thanks in advance! I'm really new at this.

提前致谢!我真的很新。

here's my code:

这是我的代码:

<form name="htmlform" method="post" action="something_sendform.php">
<table width="450px">
</tr>
<tr>
 <td valign="top">
  <label for="first_name">First Name *</label>
 </td>
 <td valign="top">
  <input  type="text" name="first_name" maxlength="50" size="30">
 </td>
</tr>

<tr>
 <td valign="top"">
  <label for="last_name">Last Name *</label>
 </td>
 <td valign="top">
  <input  type="text" name="last_name" maxlength="50" size="30">
 </td>
</tr>
<tr>
 <td valign="top">
  <label for="email">Email Address *</label>
 </td>
 <td valign="top">
  <input  type="text" name="email" maxlength="80" size="30">
 </td>

</tr>
<tr>
 <td valign="top">
  <label for="telephone">Telephone Number</label>
 </td>
 <td valign="top">
  <input  type="text" name="telephone" maxlength="30" size="30">
 </td>
</tr>
<tr>
 <td valign="top">
  <label for="comments">Comments *</label>
 </td>
 <td valign="top">
  <textarea  name="comments" maxlength="1000" cols="25" rows="6"></textarea>
 </td>

</tr>
<tr style="font-family:Orator Std">
 <td colspan="2" style="text-align:center">
  <input type="submit" value="Submit">
 </td>
</tr>
</table>
</form>

回答by John WH Smith

Use the font-familyCSS property :

使用font-familyCSS 属性:

input[type=submit]{
    font-family: 'Orator Std';
}

To be all-browsers compatible, add class="mysubmitbutton"to your button, and use input.mysubmitbuttoninstead of input[type=submit].

要与所有浏览器兼容,请添加class="mysubmitbutton"到您的按钮,并使用input.mysubmitbutton代替input[type=submit]

Edit :If you want to do this directly in the HTML code, do it on the inputtag :

编辑:如果您想直接在 HTML 代码中执行此操作,请在input标记上执行此操作:

<input type="submit" value="Submit" style="font-family:'Orator Std';" />

I am not sure that Orator Std is a native CSS font though... For custom fonts usage in HTML/CSS, see this question.

不过,我不确定 Orator Std 是否是原生 CSS 字体...对于 HTML/CSS 中的自定义字体用法,请参阅此问题

回答by Amal Murali

You're applying the styles on the wrong element. Try this:

您在错误的元素上应用了样式。尝试这个:

<input type="submit" value="Submit" style="font-family: sans-serif; font-size: 25px;">

Note that that Orator Stdis a custom font and if you want to use it, you'll have to download the font file and load it in your CSS using @font-face.

请注意,这Orator Std是一种自定义字体,如果要使用它,则必须下载字体文件并使用 .css 将其加载到 CSS 中@font-face

Also, using inline styles is generally regarded as a bad practice and it's best to apply the styles on input[type=submit]in your CSS file or inside the <style>tags. Thisquestion answers that in greater detail.

此外,使用内联样式通常被认为是一种不好的做法,最好input[type=submit]在 CSS 文件或<style>标签内应用样式。这个问题更详细地回答了这个问题。

Demo: http://jsfiddle.net/Dq3Mg/

演示:http: //jsfiddle.net/Dq3Mg/