在開發中發如今mac上數字0和1所佔的寬度不同,網上查詢須要用到等寬字體,可是瀏覽器支持的默認幾種等寬字體中文很難看,隨即引入谷歌的字體進行渲染。javascript
最近在寫一個移動端的web項目,designer設計的頁面效果圖就是使用Google Roboto Font。The Roboto Font 是Google爲Android 4.0 Ice-Cream Sandwich platform而設計的,是一個新的san-serif字集。css
在css中,我直接使用了以下的代碼:html
body{font-family:'Roboto',Roboto Lt;}
複製代碼
頁面測試時,Roboto字體在Android Platform下面是渲染出來了,可是在iphone 5s下面則出現字體不生效的狀況。java
我直接按照Google官方的quick example code來調用這個Google的在線字體庫,可是發現仍是沒有效果,同時也在stackoverflow發了問題。ios
後來,在Google Search Engine中找到了這篇文章:How to Use The Google’s Roboto Font Everywherecss3
你能夠直接看上面連接中的文章,個人解決辦法就是按照文中的思路來實現的。若是你看不懂英文,那麼你能夠看看我下面的中文解決步驟。web
下載字體包,連接是 FontSquirrel Roboto font page。spring
在打開的頁面中,選擇「Webfont kit」,而後你點擊打開的選項頁下面的"DOWNLOAD@FONT-FACE KIT"進行壓縮包下載。瀏覽器
下載完成以後,解壓到當前文件夾,你能夠看到解壓出來的web fonts目錄,打開該目錄你會發現裏面不少都是Roboto的各類字體。你直接選擇一個你想要用在web size的上傳到你的網站相關目錄下面便可,固然,你還必需要添加一段css3 @font-face代碼來進行嵌入擴展的字體到你的站點。代碼以下:(注意,src path必須是根據你我的的具體狀況來定,不是下面寫死的代碼。)bash
[
](javascript:void(0);)1 @font-face {
2 font-family: 'Roboto';
3 src: url('Roboto-Regular-webfont.eot');
4 src: url('Roboto-Regular-webfont.eot?#iefix') format('embedded-opentype'),
5 url('Roboto-Regular-webfont.woff') format('woff'),
6 url('Roboto-Regular-webfont.ttf') format('truetype'),
7 url('Roboto-Regular-webfont.svg#RobotoRegular') format('svg');
8 font-weight: normal;
9 font-style: normal;
10 }
11
12 //假如你想要擴展更多的字體庫,那麼你就能夠按照上面代碼來進行引用就行。
複製代碼
Webfonts are supported by all major browser platforms but not all in the same way. There are currently four different font formats that must be included in order to target all browsers. This includes TTF, WOFF, EOT and SVG.
You must upload your webfont kit to your website. They should be in or near the same directory as your CSS files.
A special CSS @font-face declaration helps the various browsers select the appropriate font it needs without causing you a bunch of headaches. Learn more about this syntax by reading the Fontspring blog post about it. The code for it is as follows:
@font-face{
font-family: 'MyWebFont';
src: url('WebFont.eot');
src: url('WebFont.eot?iefix') format('eot'),
url('WebFont.woff') format('woff'),
url('WebFont.ttf') format('truetype'),
url('WebFont.svg#webfont') format('svg');
}
複製代碼
We've already gone ahead and generated the code for you. All you have to do is link to the stylesheet in your HTML, like this:
<link rel="stylesheet" href="stylesheet.css" type="text/css" charset="utf-8" />
複製代碼
To take advantage of your new fonts, you must tell your stylesheet to use them. Look at the original @font-face declaration above and find the property called "font-family." The name linked there will be what you use to reference the font. Prepend that webfont name to the font stack in the "font-family" property, inside the selector you want to change. For example:
p { font-family: 'MyWebFont', Arial, sans-serif; }
複製代碼
Getting webfonts to work cross-browser can be tricky. Use the information in the sidebar to help you if you find that fonts aren't loading in a particular browser.
Having trouble getting your webfonts to load in your new website? Here are some tips to sort out what might be the problem.
This sounds like you need to work on the plumbing. You either did not upload the fonts to the correct directory, or you did not link the fonts properly in the CSS. If you've confirmed that all this is correct and you still have a problem, take a look at your .htaccess file and see if requests are getting intercepted.
The most common problem here is that you are serving the fonts from an IIS server. IIS refuses to serve files that have unknown MIME types. If that is the case, you must set the MIME type for SVG to "image/svg+xml" in the server settings. Follow these instructions from Microsoft if you need help.
The primary reason for this failure? You are still using a version Firefox older than 3.5. So upgrade already! If that isn't it, then you are very likely serving fonts from a different domain. Firefox requires that all font assets be served from the same domain. Lastly it is possible that you need to add WOFF to your list of MIME types (if you are serving via IIS.)
Are you looking at Internet Explorer on an actual Windows machine or are you cheating by using a service like Adobe BrowserLab? Many of these screenshot services do not render @font-face for IE. Best to test it on a real machine.
IE9, like Firefox, requires that fonts be served from the same domain as the website. Make sure that is the case.