字体图标是3.X的内容,到了4.x的时候,已经被拿掉了,但是它比较重要,我们还是有必要学习的。
这里字体图标就是说把那些图标做成字体,我们就可以像使用字体一样,我们怎么去设置字体,我们就可以怎么设置这个小图标。这里要注意的是我们的字体图标依托于字体文件我们就需要创建一个fonts文件。我们在3.X中下载Bootstrap文件里面有fonts文件,我们就可以引用。
其中4.x中,我们就可以外部移入,用阿里巴巴里面的iconfont就可以
网站: https://www.iconfont.cn/
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<link rel="stylesheet" href="css/iconfont.css">
<script src="js/iconfont.js"></script>
<style>
@font-face {
font-family: 'iconfont';
src: url('fonts/iconfont.eot');
src: url('fonts/iconfont.eot?#iefix') format('embedded-opentype'),
url('fonts/iconfont.woff2') format('woff2'),
url('fonts/iconfont.woff') format('woff'),
url('fonts/iconfont.ttf') format('truetype'),
url('fonts/iconfont.svg#iconfont') format('svg');
}
.iconfont {
font-family: "iconfont" !important;
font-size: 16px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon {
width: 1em;
height: 1em;
vertical-align: -0.15em;
fill: currentColor;
overflow: hidden;
}
</style>
</head>
<body>
<!-- https://www.iconfont.cn/ -->
<div class="container">
<div class="row">
<div class="col">
<span class="glyphicon glyphicon-heart" style="font-size: 5rem; color: #f00;"></span>
<button class="btn btn-success" style="font-size: 3rem;">
<span class="glyphicon glyphicon-star"></span> 陈学辉
</button>
</div>
</div>
<div class="row">
<div class="col">
<span class="iconfont" style="font-size: 5rem; color: red;"></span>
<span class="iconfont" style="font-size: 5rem; color: red;"></span>
<span class="iconfont" style="font-size: 5rem; color: red;"></span>
<span class="iconfont" style="font-size: 5rem; color: red;"></span>
</div>
</div>
<div class="row">
<div class="col">这是第二种引入方式:就是需要引入css,之后添加class
<span class="iconfont icon-icon-test3" style="font-size: 5rem; color: green;"></span>
<span class="iconfont icon-icon-test2" style="font-size: 5rem; color: green;"></span>
<span class="iconfont icon-icon-test1" style="font-size: 5rem; color: green;"></span>
<span class="iconfont icon-icon-test" style="font-size: 5rem; color: green;"></span>
</div>
</div>
<div class="row">
<div class="col">
第三中引入方式:全新的引入方式,用的是svg,跟我们的字体图标没有什么关联了,
通过svg画这个小图标,未来的主流方式,这时候就需要用到js文件了,iconfont.js,放到对应的js文件中,
然后在头部用script标签,路径引入进来,然后载来一个icon的css代码;不支持颜色调整
<svg class="icon" aria-hidden="true" style="font-size:5rem; color:blue">
<use xlink:href="#icon-icon-test"></use>
</svg>
<svg class="icon" aria-hidden="true" style="font-size:5rem; color:blue">
<use xlink:href="#icon-icon-test1"></use>
</svg>
<svg class="icon" aria-hidden="true" style="font-size:5rem; color:blue">
<use xlink:href="#icon-icon-test2"></use>
</svg>
<svg class="icon" aria-hidden="true" style="font-size:5rem; color:blue">
<use xlink:href="#icon-icon-test3"></use>
</svg>
</div>
</div>
</div>
</body>