我想在网页中使用自定义字体。但是我对HTML5和CSS几乎一无所知。我希望有一个
标签可以使用自定义字体。我将.ttf文件放在与网页相同的文件夹中。但是以下代码没有成功:
<h1 style="text-align: center"; font-family="MinecrafterReg.ttf">Welcome to Ben's Minecraft</h1>
还有其他人能帮助我吗?
将以下内容放入样式标签中:
@font-face {
font-family: MinecrafterReg;
src: url(MinecrafterReg.ttf);
font-weight:400;
<h1 style="text-align: center; font-family: MinecrafterReg">Welcome to Ben's Minecraft</h1>
@import
:<style>
@import url('https://fonts.googleapis.com/css?family=Roboto');
</style>
这不是在网站上使用自定义字体的正确方法。首先,您应该使用外部样式表,并将所有CSS放在其中。使用内联样式不是一个好的实践。其次,我认为您不能像您想要的那样链接到.ttf文件。还要注意您的代码具有错误的内联格式。font-family:not =。此外,整个内联样式需要用引号括起来。style="text-align: center; font-family: 'Sigmar One', cursive;"
话虽如此 - 您可以在文档的“head”中链接您的字体,然后使用内联样式来设置h1的样式。以下是使用Google字体的方法。希望这有所帮助!
<head>
<link href='https://fonts.googleapis.com/css?family=Sigmar+One' rel='stylesheet' type='text/css'>
</head>
<h1 style="text-align: center; font-family: 'Sigmar One', cursive;">Welcome to Ben's Minecraft</h1>
在内联样式CSS中,字体族为font-family:url('https://s3-xxxxxxxxxxxxxx/fonts/FloydsnirLTStd-Rmands.otf');