仅使用 html 为整个页面设置字体

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18705969/
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 13:12:02  来源:igfitidea点击:

Set font for whole page with ONLY html

htmlcss

提问by XD face me

Is there any way to set a global font for a web page using only html. I can't use css cause this is for a school project. Somthing like: <body font = verdana>...content...</body>

有没有办法只使用 html 为网页设置全局字体。我不能使用 css 因为这是一个学校项目。类似的东西:<body font = verdana>...content...</body>

回答by Hive7

The way to do it in HTML with inline styles would be:

使用内联样式在 HTML 中执行此操作的方法是:

<body style='font-family="sans-serif"'>

This will set the global font to sans-serif

这会将全局字体设置为 sans-serif

You can also put CSS inside a <style>tag like this:

您还可以将 CSS 放入这样的<style>标签中:

<style>
    * {
      font-family: sans-serif;
    }
</style>

This will give every element a font of sans-serif

这会给每个元素一个字体 sans-serif

For custom fonts you can use Google Fonts

对于自定义字体,您可以使用Google Fonts

Edit this is the way to achieve it with pure HTML:

编辑这是使用纯 HTML 实现它的方法:

After the <body>tag, add the <font>tag with the face attribute of the font you'd like to use. Example usage:

<body>标签之后,添加<font>带有您要使用的字体的 face 属性的标签。用法示例:

Fiddle Demo:

小提琴演示:

http://jsfiddle.net/yHRU7/

http://jsfiddle.net/yHRU7/

HTML:

HTML:

<body>
    <font face='verdana'>
        <div class='htmlVersion'>No css</div>
    </font>
    <div class='cssVersion'>No Extra Html</div>
</body>

CSS:

CSS:

.cssVersion {
    font-family: verdana;
}

As you can see there is no difference between the results. I advise that normal stylesheets are used - the method used in the CSS version. This is more maintainable and standard.

如您所见,结果之间没有区别。我建议使用普通样式表 - CSS 版本中使用的方法。这更易于维护和标准化。

回答by Tib

You can apply css in html with inline cssbut it's highly recommanded to use an external stylesheet

您可以使用内联css 在 html 中应用 css,但强烈建议使用外部样式表

<body style="font-family:'Verdana'">