Home Web Front-end CSS Tutorial Colorful css3 personalized fonts

Colorful css3 personalized fonts

Jul 16, 2017 pm 03:48 PM
css css3

When making pages, we often use "font-family" to define fonts. However, whether the fonts we define using "font-family" can be rendered in the user's browser depends on the user's computer. Whether the fonts we defined are installed on it. On the Internet, we can often see that some foreign websites use some uncommon and beautiful fonts, and these fonts are generally not installed on users’ computers. So today we will introduce how to use them on the page. The font is not installed on the user's computer.

css3 @font-face

It is actually inaccurate to say that @font-face is a new attribute of CSS3, because this feature is already supported in CSS2, and IE5 has already started to support it. , but the way it is implemented in IE is through the eot font format. Unfortunately, other browsers do not support this format.

In web pages, we can use the font-family attribute of CSS to define fonts. However, whether the defined fonts can be displayed correctly on the user's computer depends on whether the user's computer is installed. the font. We often see some foreign personal websites using very beautiful fonts, but these fonts are usually not installed on the user's computer, so it cannot be achieved using the font-family attribute. Today we will introduce the use of @font- face implements personalized fonts.

CSS3 @font-face

It is not accurate to say that @font-face is a new feature of CSS3, because CSS2 already supports this feature. And Internet Explorer has supported it as early as version 5, but IE implements it through its own eot (Embeded Open Type) font format, and other browsers do not support this format. @font-face supports the following attributes:

Font-family: Set the font name of the text.
 font-style: Set text style.
 font-variant: Set whether the text is uppercase or lowercase.
 font-weight: Set the thickness of the text.
 font-stretch: Set whether the text is stretched horizontally.
 font-size: Set the text font size.
 src: Set the relative path or absolute path of the custom font.
@font-face browser compatibility is as follows:

A simple example

First declare a name For the font of ChantelliAntiquaRegular, there is an old way of writing it like this:


@font-face {
    font-family: "ChantelliAntiquaRegular";
    src: url("Chantelli_Antiqua-webfont.eot");
    src: local("☺"), url("Chantelli_Antiqua-webfont.woff") format("woff"), url("Chantelli_Antiqua-webfont.ttf") format("truetype"), url("Chantelli_Antiqua-webfont.svg#webfontZjhIjbDc") format("svg");
    font-weight: normal;
    font-style: normal;
}
Copy after login

The first src is compatible with IE, and the second src is compatible with other browsers. local("☺") is a hack writing method to avoid loading fonts from the client. This writing method has BUG in the Android system. The improvement plan is to declare two @font-face, as follows:


@font-face {
    font-family: "ChantelliAntiquaRegular";
    src: url("Chantelli_Antiqua-webfont.eot");
}
 
@font-face {
    font-family: "ChantelliAntiquaRegular";
    src: url(//:) format("no404"), url("Chantelli_Antiqua-webfont.woff") format("woff"), url("Chantelli_Antiqua-webfont.ttf") format("truetype"), url("Chantelli_Antiqua-webfont.svg#webfontMFqI76bT") format("svg");
    font-weight: normal;
    font-style: normal;
}
Copy after login

We first declare a @font-face that refers to the eot font file to ensure that it can work properly in IE. The second @font-face refers to multiple font formats for compatibility with other browsers. converter, they will look sequentially until a supported format is found, which means the same font needs to be available in multiple formats. url(//:) format("no404") is a Bulletproof writing method.

Other HTML and CSS codes are as follows:


##

.font-face-display {
    font: 66px ChantelliAntiquaRegular, Helvetica, sans-serif;
}
 
<p class="font-face-display">Take me to your heart</p>
Copy after login
The most important effect is as follows:

Free font website Font Squirrel

Font Squirrel is an excellent free font resource website that collects many high-quality fonts for web designers to download for free, as well as a font format The generation tool @font-face generator uploads a font file and can generate multiple font formats and CSS codes, which is very useful. If you need some great free English fonts, this is the place to go.

If you want a colorful page, you need more font styles. People have come up with many font alternatives. In addition to the @font-face solution, there are also sIFR, Cufon, Typeface.js, etc., and .webfont. To put it simply, .webfont has an access permission table embedded in the font. The browser can read this permission information and decide whether these fonts should be downloaded and rendered. In addition, Typekit is also a solution worthy of attention, which places fonts on a third-party server for calling. The advantages and disadvantages of these solutions will be introduced in detail later.

The above is the detailed content of Colorful css3 personalized fonts. For more information, please follow other related articles on the PHP Chinese website!

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months 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)

How to write split lines on bootstrap How to write split lines on bootstrap Apr 07, 2025 pm 03:12 PM

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

How to insert pictures on bootstrap How to insert pictures on bootstrap Apr 07, 2025 pm 03:30 PM

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to resize bootstrap How to resize bootstrap Apr 07, 2025 pm 03:18 PM

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

How to set up the framework for bootstrap How to set up the framework for bootstrap Apr 07, 2025 pm 03:27 PM

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to use bootstrap button How to use bootstrap button Apr 07, 2025 pm 03:09 PM

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

How to view the date of bootstrap How to view the date of bootstrap Apr 07, 2025 pm 03:03 PM

Answer: You can use the date picker component of Bootstrap to view dates in the page. Steps: Introduce the Bootstrap framework. Create a date selector input box in HTML. Bootstrap will automatically add styles to the selector. Use JavaScript to get the selected date.

How to use bootstrap in vue How to use bootstrap in vue Apr 07, 2025 pm 11:33 PM

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

See all articles