将字体系列应用于整个页面并不起作用

时间:2017-10-15 08:05:24

标签: html css

我在网上查了但没有帮助我,有人说使用这段代码:

*{
      font-family: Verdana;
 }

我试过把它放在体内,头部,没什么,有人说不是用来使用身体,试过它,没有工作。我看到如果我的代码甚至可以正常工作,我试图用选择器更改单个段落的字体并且它有效。

<body>
          *{
            font-family: Verdana;
          }

          <a class="btn btn-danger" href="http:www.yahoo.com"> what </a>
          <a class="btn btn-success"> owo </a>
           <style>
          .btn {
            font-size: 55px;
          }
          .btn-danger {
            background-color: red;
          }
          .btn-success {
            background: rgba(128, 0, 0, .25);
            font-family: fantasy;
          }
          </style>
          <p class="Cx"> blacks111 </p>
          <style>
          .Cx {
            background-color: grey

          }
          </style>
</body>

2 个答案:

答案 0 :(得分:0)

为了使你的风格有效,你应该将它们包裹在demo中,就像这样(否则它不会起作用):

<style></style>

当你被告知把它放在身体或头部时,他们可能正在谈论css选择器,而不是HTML标签。

根据MDN:

  

在CSS中,选择器用于定位Web上的HTML元素   我们想要设计风格的网页。

You can read more about CSS Selectors here

答案 1 :(得分:-2)

以下是解决方案: 使用!important是最重要的属性。 HTML:

<a class="btn btn-danger" href="http:www.yahoo.com"> what </a>
      <a class="btn btn-success"> owo </a>
       <style>
      .btn {
        font-size: 55px;
      }
      .btn-danger {
        background-color: red;
      }
      .btn-success {
        background: rgba(128, 0, 0, .25);

      }
      </style>
      <p class="Cx"> blacks111 </p>
      <style>
      .Cx {
        background-color: grey

      }
      </style>

CSS:

*{
        font-family: Verdana !important;
      }