Table of Contents
1.基本操作:
注释:
2.字体系列:
系列分类:
示例:
总结特点:
3.使用CSS指定字体系列:
浏览器的幕后工作:
4.Wed字体的使用
 使用步骤:
5.调整字体大小
指定font-size的一些方法:
指定字体大小的建议:
示图:
6.改变字体粗细:
7.为字体增加风格:
8.颜色样式:
指定颜色的方法:
文本装饰:
Home Web Front-end HTML Tutorial 增加字体和颜色样式-CSS_html/css_WEB-ITnose

增加字体和颜色样式-CSS_html/css_WEB-ITnose

Jun 24, 2016 am 11:34 AM

通过使用CSS,控制文本的字体,风格和颜色

1.基本操作:

 

 1 body{ 2     font-family: Verdana, Geneva, Tahoma, sans-serif 3 } 4  5 body{ 6     font-size: 14px 7 } 8  9 body{10     color: silver11 }12 13 body{14     font-weight: bold15 }16 17 body{18     text-decoration: underline19 }
Copy after login

注释:

  • font-family:定制页面中使用的字体
  • font-size:控制字体大小
  • color:为文本设置颜色
  • font-weight:影响字体的粗细
  • text-decoration:为文本增加更多风格
  • 2.字体系列:

    系列分类:

  • sans-serif
  • serif
  • monospace
  • cursive
  • fanstasy
  • 衬线:是字母末端的装饰性的小线
  • 示例:

  • sans-serif没有衬线,适合阅读
  • Serif:有衬线,看起来传统,多出现在报纸
  • Monospace:字体包含固定宽度的字符,例如:一个“i”水平的宽度和一个“m”相同,主要用于显示软件代码示例
  • Cursive:有些看似手写,有时会在标题上使用
  • Fantasy:含有某种风格的装饰性字体:
  • 总结特点:

  • serif字体看起来很高雅,传统。
  • sans-serif字体外观清晰,可读性好
  • monospace 像打字机打出来的
  • Cursive和fantasy字体给人有趣或者很有分格的感觉
  • 3.使用CSS指定字体系列:

    浏览器的幕后工作:

    1 body{2     font-family: Verdana, Geneva, Tahoma, sans-serif3 }
    Copy after login

    注释:

  • 我们为body指定了4个候选字体
  • 浏览器会从左往右进行选择
  • 如果浏览器检查到用户没有定制的第一个字体,会接着检查第二个
  • 直到查找到用户有的字体
  • 如果前面3种特定的字体都没找到,浏览器就会使用默认的sans-serif字体
  • 示图:

    4.Wed字体的使用

    我们都会有这样一个想法,

    自己辛苦设计的页面,有很酷的字体,

    不希望到了用户手里,却全都变成了默认。。。

    因此:有了@font-face规则

    使用步骤:

    1. 找到一个字体,可以是自己所有的,也可以使用提供字体网站授权给你使用的
    2. 确保有所需字体的格式,一般建议使用web开放字体格式(.woff)
    3. 把字体文件放在web上,或者利用在线字体服务为你托管这些文件。但无论哪种,你都需要字体文件的URL
    4. 在CSS中增加@font-face属性
    5. 在CSS中使用@font-face属性

    示例代码:

     1 @font-face{ 2     /*我们为我们的字体设立一个名字*/ 3     font-family: "JJStyle One"; 4     /*浏览器会加载src指定的字体文件,直到找到他能支持的一个文件*/ 5     src: ur1("http://wickedlysmart.com/hfhtmlcss/chapter8/journal/EmblemaOne-Regular.woff") 6          ur1("http://wickedlysmart.com/hfhtmlcss/chapter8/journal/EmblemaOne-Regular.ttf") 7 } 8  9 10 h1{11     /*使用我们指定的字体名*/12     font-family: "JJStyle One",sans-serif;13 }
    Copy after login

    注意:

  • 可以定制多个字体,但需要保证服务器上有相应的字体文件,
  • 而且要分别创建一个单独的@font-face规则,且名字唯一
  • 5.调整字体大小

    大多数默认的字体都不太美观,

    为此,作为设计者,

    都需要知道如何指定字体大小。

    指定font-size的一些方法:

    1. PX
    2. %
    3. em
    4. 关键字

    示例代码:

     1 body{ 2     /*字体的高度为14像素*/ 3     font-size: 14px 4 } 5  6 h1{ 7     /*字体大小为相对于另一个字体大小的150%,这里是相对于body字体的大小*/ 8     font-size:150% 9 }10 11 h2{12     /*相对于另一个字体1.2倍*/13     font-size: 1.2em;14 }15 16 h3{17     font-size: small18     /*关键字有:xx-small,x-small,small,medium,large,x-large,xx-large*/19 }
    Copy after login

    指定字体大小的建议:

    1. 选择一个关键字(推荐samll或mediun),指定它为body规则的字体大小。相当于页面默认大小
    2. 使用em或百分数,相对于body字体大小指定其它元素的字体大小(使用em还是百分数由你决定,因为效果都一样)

     1 body{ 2     font-family: Verdana, Geneva, Tahoma, sans-serif; 3     /*字体的高度为14像素*/ 4     font-size: small 5 } 6  7 h1{ 8     font-family: sans-serif; 9     /*字体大小为相对于另一个字体大小的150%,这里是相对于body字体的大小*/10     font-size:150%11 }12 13 h2{14     /*相对于另一个字体1.2倍*/15     font-size: 1.2em;16 }
    Copy after login

    示图:

    6.改变字体粗细:

  • font-weight:bold
  • font-weight:normal
  • 7.为字体增加风格:

    斜体:

    1. not italic
    2. italic(文本向右倾斜,另外衬线还有弯曲)

    倾斜:

    1. not oblique
    2. oblique(普通文本向右倾斜)

    注意:

  • 一般来说,不论你指定什么风格,结果都不确定,有时是斜体,有时是倾斜。
  • 所以,除非真的对你很重要,不然完全可以就用斜体,不用担心差别
  • 8.颜色样式:

    指定颜色的方法:

  • 颜色名
  • 按红绿蓝对百分比指定
  • 十六进制码
  • 1.按名字指定

    1 body{2     background-color: silver;<br />3 }
    Copy after login

    2.用红绿蓝值指定颜色

    1 body{2     /*rgb:红绿蓝 颜色的缩写*/3     background-color: rgb(80%, 40%, 0%);4 }5 h1{6     background-color: rgb(204,102,0);7 }
    Copy after login

    3.用16进制码指定

    1 h2{2     background-color: #cc66003 }
    Copy after login

    注释:

  • 十六进制码以#开头
  • 前两位数字表示红色的分量,中间两位是绿色,后面两位是蓝色
  • 上图代码的“CC”的分量的计算步骤与解释如下图
  • 文本装饰:

     1 em{ 2     /*使<em>元素有一个从文本中间穿过的横线*/ 3     text-decoration: line-through; 4 } 5  6  7 em{ 8     /*使<em>元素有一个上画线和下划线*/ 9     text-decoration: underline overline;10 }11 12 em{13     /*使<em>元素没有任何装饰*/14     text-decoration: none;15 }16 17 h1,h2{18     color: #cc6600;19     /*在下滑框上加一条细的虚线*/20     border-bottom:thin dotted #aabbcc;21 }
    Copy after login

     

     

    The end--

     

    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Article

    Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
    4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
    Nordhold: Fusion System, Explained
    1 months ago By 尊渡假赌尊渡假赌尊渡假赌
    Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
    4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
    Clair Obscur: Expedition 33 - How To Get Perfect Chroma Catalysts
    2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Hot Topics

    Java Tutorial
    1677
    14
    PHP Tutorial
    1278
    29
    C# Tutorial
    1257
    24
    HTML: The Structure, CSS: The Style, JavaScript: The Behavior HTML: The Structure, CSS: The Style, JavaScript: The Behavior Apr 18, 2025 am 12:09 AM

    The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

    The Future of HTML, CSS, and JavaScript: Web Development Trends The Future of HTML, CSS, and JavaScript: Web Development Trends Apr 19, 2025 am 12:02 AM

    The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

    The Future of HTML: Evolution and Trends in Web Design The Future of HTML: Evolution and Trends in Web Design Apr 17, 2025 am 12:12 AM

    The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

    HTML vs. CSS vs. JavaScript: A Comparative Overview HTML vs. CSS vs. JavaScript: A Comparative Overview Apr 16, 2025 am 12:04 AM

    The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

    HTML vs. CSS and JavaScript: Comparing Web Technologies HTML vs. CSS and JavaScript: Comparing Web Technologies Apr 23, 2025 am 12:05 AM

    HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

    Beyond HTML: Essential Technologies for Web Development Beyond HTML: Essential Technologies for Web Development Apr 26, 2025 am 12:04 AM

    To build a website with powerful functions and good user experience, HTML alone is not enough. The following technology is also required: JavaScript gives web page dynamic and interactiveness, and real-time changes are achieved by operating DOM. CSS is responsible for the style and layout of the web page to improve aesthetics and user experience. Modern frameworks and libraries such as React, Vue.js and Angular improve development efficiency and code organization structure.

    What is the difference between <strong>, <b> tags and <em>, <i> tags? What is the difference between <strong>, <b> tags and <em>, <i> tags? Apr 28, 2025 pm 05:42 PM

    The article discusses the differences between HTML tags , , , and , focusing on their semantic vs. presentational uses and their impact on SEO and accessibility.

    HTML as a Markup Language: Its Function and Purpose HTML as a Markup Language: Its Function and Purpose Apr 22, 2025 am 12:02 AM

    The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

    See all articles