Html 如何在 div 中设置字体系列和字体大小?

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

How can I set the font-family & font-size inside of a div?

htmlcssfont-sizefont-family

提问by ericg

This is my complete test html:

这是我完整的测试 html:

<!DOCTYPE>
<html>
    <head>
        <title>DIV Font</title>

        <style>
            .my_text
            {
                font-family:    Arial, Helvetica, sans-serif
                font-size:      40px;
                font-weight:    bold;
            }
        </style>
    </head>

    <body>
        <div class="my_text">some text</div>
    </body>
</html>

The font-family & font-size attributes are being ignored.

font-family 和 font-size 属性被忽略。

page result

页面结果

Why? Why is font-weight used? What do I need to do so I can specify the font-family & font-size?

为什么?为什么使用字体粗细?我需要做什么才能指定字体系列和字体大小?

Thank you

谢谢

回答by jaunt

You need a semicolon after font-family: Arial, Helvetica, sans-serif. This will make your updated code the following:

后需要一个分号font-family: Arial, Helvetica, sans-serif。这将使您的更新代码如下:

<!DOCTYPE>
<html>
    <head>
        <title>DIV Font</title>

        <style>
            .my_text
            {
                font-family:    Arial, Helvetica, sans-serif;
                font-size:      40px;
                font-weight:    bold;
            }
        </style>
    </head>

    <body>
        <div class="my_text">some text</div>
    </body>
</html>

回答by Anthony Rojas

Append a semicolon to the following line to fix the issue.

将分号附加到以下行以解决问题。

font-family:    Arial, Helvetica, sans-serif;