CSS/字体:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
 
(未显示同一用户的10个中间版本)
第1行: 第1行:
== 字号 ==
浏览器限制字号最小 12px,但是可以通过设置 <syntaxhighlight lang="css" inline>
transform: scale(0.7);
</syntaxhighlight> 进行更小化处理。
== 格式 ==
== 格式 ==
=== .otf ===
=== .otf ===
第7行: 第11行:
=== TTF ===
=== TTF ===
旧版Safari,Android和iOS浏览器的后备版
旧版Safari,Android和iOS浏览器的后备版
== onlinefontconverter ==
== onlinefontconverter ==
== 组合方案 ==
== 组合方案 ==
第36行: 第41行:
* http://www.fontsquirrel.com/tools/webfont-generator
* http://www.fontsquirrel.com/tools/webfont-generator
* http://everythingfonts.com/ttf-to-woff2
* http://everythingfonts.com/ttf-to-woff2
* https://www.fontke.com/tool/convfont/
=== 转为 js ===
=== 转为 js ===
* http://cufon.shoqolate.com/generate/
* http://cufon.shoqolate.com/generate/
第52行: 第59行:
line-height:1.5em;
line-height:1.5em;
</syntaxhighlight>
</syntaxhighlight>
== 引用字体 ==
=== 引用字体跨域 ===
==== base64 编码 ====
=== 动态引入 ===
方法一
<syntaxhighlight lang="css">
@font-face { /* 有多少个字体要写多少个“@font-face {}”块 */
font-family:;
src: url('Coda.eot'); /* IE9 */
src: url('Coda.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
  url('Coda.woff') format('woff'), /* Modern Browsers */
  url('Coda.ttf')  format('truetype'), /* Safari, Android, iOS */
  url('Coda.svg#Coda') format('svg'); /* Legacy iOS */
}</syntaxhighlight>
方法二
==== document.fonts API ====
<syntaxhighlight lang="javascript">
// 浏览器是否支持
if (!document.fonts) {
  alert('抱歉,当前浏览器兼容性较差,会影响操作体验,请更换最新版谷歌浏览器进行操作');
}
// 检验字体是否已经安装
if (document.fonts.check(`16px Noto Serif CJK SC`, '上')) {
    return Promise.resolve(true);
}
// 加载字体
const fontface = new FontFace(name, `url(xxx)`);
document.fonts.add(fontface);
fontface.load();
fontface.loaded.then(() => {
    // 字体加载完毕,可使用
}).catch(err => {
    // 字体加载失败
});</syntaxhighlight>
vue 的写法:
<syntaxhighlight lang="javascript">
//加载字体文件
  obj格式,cssValue为自定义字体的名字,url为自定义字体的文件路径
    loadFont(obj){
        if(document.fonts&&!this.checkFont(obj.cssValue))
        {
            let that=this;
            let fontFamily=obj.cssValue;
            console.log(obj);
            let fontFace = new FontFace(obj.cssValue, `local('${obj.cssValue}'),url('${obj.url}') format('ttf'),url('${obj.url}')`);
            fontFace.load().then(function(loadedFontFace) {
                document.fonts.add(loadedFontFace);
                that.canvasDemo.updateTextFontFamily(fontFamily);
            });
        }
    },
    //检测字体文件是否已加载
    checkFont(name){
        let values=document.fonts.values();
        let isHave=false;
        let item=values.next();
        while(!item.done&&!isHave)
        {
            let fontFace=item.value;
            if(fontFace.family==name)
            {
                isHave=true;
            }
            item=values.next();
        }
        return isHave;
}
</syntaxhighlight>
{{Unknown}}
== 字体预加载 ==
<blockquote><pre>
font-display: swap;</pre></blockquote>
* font-display: swap:
*: 浏览器直接使用 font-family 中最先匹配到的已经能够使用的字体,然后当 font-family 中更靠前的字体成功载入时,切换到更靠前的字体。
* font-display: fallback:
*: 浏览器会先等待最靠前的字体加载,如果没加载到就不显示任何东西,过程大约持续100ms,之后按照顺序显示已经成功载入的字体。在此之后有大约3s的时间来提供切换到加载完毕的更靠前的字体。
* font-display: optional:
*: 浏览器会先等待最靠前的字体加载,如果没加载到就不显示任何东西,过程大约持续100ms,之后字体就不会再更改(第一次打开某页面的时候都会使用fallabck字体,字体被下载但是没被使用,之后打开时会使用缓存中的字体)。


== 单位 ==
== 单位 ==
第87行: 第176行:
安装read-edid软件包并<code>sudo get-edid | parse-edid | grep DisplaySize</code>在终端中运行命令。它的输出将为您提供显示器的实际大小(以毫米为单位)。如果不是,请使用标尺。
安装read-edid软件包并<code>sudo get-edid | parse-edid | grep DisplaySize</code>在终端中运行命令。它的输出将为您提供显示器的实际大小(以毫米为单位)。如果不是,请使用标尺。
== fallback 机制 ==
== fallback 机制 ==
== 字体子集化 ==
* 腾讯:font-spider
* 百度:font-min
* 阿里巴巴:icon-font font-carrier
== error ==
== error ==
=== 垂直居中偏移问题 ===
=== 垂直居中偏移问题 ===
第94行: 第188行:
==== align-items ====
==== align-items ====
==== inline-block段落间有缝隙 ====
==== inline-block段落间有缝隙 ====
== 参考 ==
* http://randsco.com/index.php/2009/07/04/p680
* https://alistapart.com/blog/topic/typography-web-fonts/