公告:魔扣目录网为广大站长提供免费收录网站服务,提交前请做好本站友链:【 网站目录:https://www.morko.net 】, 免友链快审服务(50元/站),

点击这里在线咨询客服
新站提交
  • 网站:51998
  • 待审:31
  • 小程序:12
  • 文章:1030137
  • 会员:747

CSS(即层叠样式表)是控制网页视觉呈现的强大工具。其一方面是能够调整页面上文本元素的字体大小。这可以通过使用 font-size 属性来完成。

要为特定元素设置特定字体大小,我们将类或 ID 选择器与 font-size 属性结合使用。

在本文中,我们将看到多个使用 CSS 更改字体大小的示例 –

通过使用 font-size 属性,我们可以为特定元素或类设置特定的字体大小。例如,要将 元素的字体大小设置为 18 像素,我们将使用以下代码 –

P{
   font-size:18px;
}

登录后复制

示例

<html>
<head>
   <title>How to change the font size using CSS</title>
   <style>
      .p1{
         font-size:20px;
      }
   </style>
</head>
<body>
   <h1>Welcome to tutorialspoint</h1>
   <p class="p1">Change the font size using CSS</p>
   <p>This is normal paragraph</p> 
</body>
</html>

登录后复制

我们还可以使用 font-size 属性来设置相对字体大小,例如更大或更小,这将更改相对于父元素字体大小的字体大小。为此,我们将使用以下代码 –

P{
   font-size:larger;
}

登录后复制

示例

<html>
<head>
   <title>How to change the font size using CSS</title>
   <style>
      .p1{
         font-size:large;
      }
      .p2{
         font-size:small;
      }
   </style>
</head>
<body>
   <h1>Welcome to tutorialspoint</h1>
   <p class="p1">Change the font size using CSS - Large font</p>
   <p class="p2">Change the font size using CSS - Small font</p>
   <p>This is normal paragraph</p>
</body>
</html> 

登录后复制

另一种定位特定单词的方法是使用 :not css 选择器。这允许定位元素中除唯一单词之外的所有单词。例如 –

CSS

p span:not(.unique) {
   font-size: 18px;
} 

登录后复制

HTML

<p>This is a <span class="not-unique">not unique</span> word, but this <span class="not-unique">word</span> is <span class="unique">unique</span>.</p> 

登录后复制

示例

<html>
   <head>
      <title>How to change the font size using CSS</title>
      <style>
         p span:not(.unique) {
            font-size: 20px; 
         }
      </style>
   </head>
   <body>
      <p>Lorem Ipsum is simply dummy text of <span class="notunique">not unique</span> the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, <span class="not-unique">not unique</span> when an unknown printer took a galley of type and scrambledg,</p>
   </body>
</html>

登录后复制

CSS 中的 font-size 属性允许精确控制网页上文本元素的大小。无论我们是想为特定元素设置特定的字体大小、根据父元素的字体大小调整字体大小还是针对特定的单词,CSS 都提供了必要的工具来完成此操作。

以上就是如何使用CSS改变字体大小?的详细内容,更多请关注www.92cms.cn其它相关文章!

分享到:
标签:CSS 如何使用 字体大小 改变
用户无头像

网友整理

注册时间:

网站:5 个   小程序:0 个  文章:12 篇

  • 51998

    网站

  • 12

    小程序

  • 1030137

    文章

  • 747

    会员

赶快注册账号,推广您的网站吧!
最新入驻小程序

数独大挑战2018-06-03

数独一种数学游戏,玩家需要根据9

答题星2018-06-03

您可以通过答题星轻松地创建试卷

全阶人生考试2018-06-03

各种考试题,题库,初中,高中,大学四六

运动步数有氧达人2018-06-03

记录运动步数,积累氧气值。还可偷

每日养生app2018-06-03

每日养生,天天健康

体育训练成绩评定2018-06-03

通用课目体育训练成绩评定