我们有一个项目,大量使用字形图标。Bootstrap v4完全删除了glyphicon字体。
Bootstrap V4随附的图标是否等效?
我们有一个项目,大量使用字形图标。Bootstrap v4完全删除了glyphicon字体。
Bootstrap V4随附的图标是否等效?
Answers:
您可以将Font Awesome和Github Octicons用作Glyphicons的免费替代品。
Bootstrap 4也从Less切换到Sass,因此您可以将字体的Sass(SCSS)整数化到构建过程中,以为项目创建单个CSS文件。
另请参阅https://getbootstrap.com/docs/4.1/getting-started/build-tools/以了解如何设置工具:
/bootstrap
目录,然后运行npm install
以安装package.json中列出的本地依赖项。gem install bundler
,最后运行bundle install
。这将安装所有Ruby依赖项,例如Jekyll和插件。字体很棒
font-awesome/scss
文件夹复制到您的/ bootstrap文件夹中打开您的SCSS /bootstrap/bootstrap.scss
并在该文件末尾写下以下SCSS代码:
$fa-font-path: "../fonts";
@import "../font-awesome/scss/font-awesome.scss";
请注意,您还必须将字体文件从复制font-awesome/fonts
到dist/fonts
或$fa-font-path
在上一步中设置的任何其他公用文件夹
npm run dist
用Font-Awesome重新编译代码Github Octicons
octicons
文件夹复制到您的/bootstrap
文件夹中打开您的SCSS /bootstrap/bootstrap.scss
并在该文件末尾写下以下SCSS代码:
$fa-font-path: "../fonts";
@import "../octicons/octicons/octicons.scss";
请注意,您还必须将字体文件从复制font-awesome/fonts
到dist/fonts
或$fa-font-path
在上一步中设置的任何其他公用文件夹
npm run dist
用Octicons重新编译代码雕ly
在Bootstrap网站上,您可以阅读:
包括来自Glyphicon Halflings集的超过250种字体格式的字形。通常不会免费提供Glyphicons Halflings,但其创建者已使它们免费提供给Bootstrap。谢谢,我们只要求您在可能的情况下包括指向Glyphicons的链接。
据我了解,您可以免费使用这250个字形,但不受Bootstrap限制,但不限于版本3专有。因此,您也可以将它们用于Bootstrap 4。
bootstrap/scss
文件夹中$bootstrap-sass-asset-helper: false;
$icon-font-name: 'glyphicons-halflings-regular';
$icon-font-svg-id: 'glyphicons_halflingsregular';
$icon-font-path: '../fonts/';
@import "glyphicons";
npm run dist
用Glyphicons重新编译代码请注意,Bootstrap 4需要Post CSS Autoprefixer进行编译。当使用静态Sass编译器编译CSS时,您必须随后运行Autoprefixer。
您可以在此处找到有关与Bootstrap 4 SCSS混合的更多信息。
您也可以使用Bower安装上述字体。使用Bower Font Awesome安装文件时,请bower_components/components-font-awesome/
注意Github Octicons将设置octicons/octicons/octicons-.scss
为主要文件,而您应该使用octicons/octicons/sprockets-octicons.scss
。
以上所有内容将所有CSS代码(包括一个文件)编译到一个文件中,该文件仅需要一个HTTP请求。另外,您也可以从CDN加载Font-Awesome字体,这在许多情况下也可以很快。CDN上的两种字体也都包含字体文件(使用data-uri,老式浏览器可能不支持)。因此,请根据要支持的其他浏览器来考虑哪种解决方案最适合您的情况。
对于Font Awesome,请将以下代码粘贴到<head>
您网站的HTML部分:
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
还可以尝试使用Yeoman生成器来构建前端Bootstrap 4 Web应用程序,以使用Font Awesome或Github Octicons测试Bootstrap 4。
从Glyphicons迁移到Font Awesome非常容易。
包括对Font Awesome的引用(在本地或使用CDN)。
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
然后运行搜索,并在要搜索的位置glyphicon glyphicon-
替换并替换为fa fa-
。大多数CSS类名称是相同的。不过,其中一些已更改,因此您必须手动修复它们。
fa fa-
已折旧。他们的网站上现在显示fas fa-
,并显示以下消息:The fa prefix has been deprecated in version 5. The new default is the fas solid style and the fab style for brands.
Bootstrap 3中的glyphicons.less文件可在GitHub上找到。 https://github.com/twbs/bootstrap/blob/master/less/glyphicons.less
它需要以下变量:
@icon-font-path: "../fonts/";
@icon-font-name: "glyphicons-halflings-regular";
@icon-font-svg-id: "glyphicons_halflingsregular";
然后,您可以将.less文件转换为可以直接使用的.css文件。您可以在线访问lesscss.org/less-preview/。在这里,我已经为您完成了此操作,将其另存为glyphicons.css并将其包含在您的HTML文件中。
<link href="https://stackoverflow.com/Content/glyphicons.css" rel="stylesheet" />
您还需要Bootstrap 3软件包中的Glyphicon字体,将它们放在/ fonts /目录中。
现在,您可以像往常一样继续在Bootstrap 4中使用Glyphicons。
如果只需要CSS中的glyphicon类:
@font-face{font-family:'Glyphicons Halflings';src:url('https://netdna.bootstrapcdn.com/bootstrap/3.0.0/fonts/glyphicons-halflings-regular.eot');src:url('https://netdna.bootstrapcdn.com/bootstrap/3.0.0/fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'),url('https://netdna.bootstrapcdn.com/bootstrap/3.0.0/fonts/glyphicons-halflings-regular.woff') format('woff'),url('https://netdna.bootstrapcdn.com/bootstrap/3.0.0/fonts/glyphicons-halflings-regular.ttf') format('truetype'),url('https://netdna.bootstrapcdn.com/bootstrap/3.0.0/fonts/glyphicons-halflings-regular.svg#glyphicons-halflingsregular') format('svg');}.glyphicon{position:relative;top:1px;display:inline-block;font-family:'Glyphicons Halflings';font-style:normal;font-weight:normal;line-height:1;-webkit-font-smoothing:antialiased;}
.glyphicon-asterisk:before{content:"\2a";}
.glyphicon-plus:before{content:"\2b";}
.glyphicon-euro:before{content:"\20ac";}
.glyphicon-minus:before{content:"\2212";}
.glyphicon-cloud:before{content:"\2601";}
.glyphicon-envelope:before{content:"\2709";}
.glyphicon-pencil:before{content:"\270f";}
.glyphicon-glass:before{content:"\e001";}
.glyphicon-music:before{content:"\e002";}
.glyphicon-search:before{content:"\e003";}
.glyphicon-heart:before{content:"\e005";}
.glyphicon-star:before{content:"\e006";}
.glyphicon-star-empty:before{content:"\e007";}
.glyphicon-user:before{content:"\e008";}
.glyphicon-film:before{content:"\e009";}
.glyphicon-th-large:before{content:"\e010";}
.glyphicon-th:before{content:"\e011";}
.glyphicon-th-list:before{content:"\e012";}
.glyphicon-ok:before{content:"\e013";}
.glyphicon-remove:before{content:"\e014";}
.glyphicon-zoom-in:before{content:"\e015";}
.glyphicon-zoom-out:before{content:"\e016";}
.glyphicon-off:before{content:"\e017";}
.glyphicon-signal:before{content:"\e018";}
.glyphicon-cog:before{content:"\e019";}
.glyphicon-trash:before{content:"\e020";}
.glyphicon-home:before{content:"\e021";}
.glyphicon-file:before{content:"\e022";}
.glyphicon-time:before{content:"\e023";}
.glyphicon-road:before{content:"\e024";}
.glyphicon-download-alt:before{content:"\e025";}
.glyphicon-download:before{content:"\e026";}
.glyphicon-upload:before{content:"\e027";}
.glyphicon-inbox:before{content:"\e028";}
.glyphicon-play-circle:before{content:"\e029";}
.glyphicon-repeat:before{content:"\e030";}
.glyphicon-refresh:before{content:"\e031";}
.glyphicon-list-alt:before{content:"\e032";}
.glyphicon-flag:before{content:"\e034";}
.glyphicon-headphones:before{content:"\e035";}
.glyphicon-volume-off:before{content:"\e036";}
.glyphicon-volume-down:before{content:"\e037";}
.glyphicon-volume-up:before{content:"\e038";}
.glyphicon-qrcode:before{content:"\e039";}
.glyphicon-barcode:before{content:"\e040";}
.glyphicon-tag:before{content:"\e041";}
.glyphicon-tags:before{content:"\e042";}
.glyphicon-book:before{content:"\e043";}
.glyphicon-print:before{content:"\e045";}
.glyphicon-font:before{content:"\e047";}
.glyphicon-bold:before{content:"\e048";}
.glyphicon-italic:before{content:"\e049";}
.glyphicon-text-height:before{content:"\e050";}
.glyphicon-text-width:before{content:"\e051";}
.glyphicon-align-left:before{content:"\e052";}
.glyphicon-align-center:before{content:"\e053";}
.glyphicon-align-right:before{content:"\e054";}
.glyphicon-align-justify:before{content:"\e055";}
.glyphicon-list:before{content:"\e056";}
.glyphicon-indent-left:before{content:"\e057";}
.glyphicon-indent-right:before{content:"\e058";}
.glyphicon-facetime-video:before{content:"\e059";}
.glyphicon-picture:before{content:"\e060";}
.glyphicon-map-marker:before{content:"\e062";}
.glyphicon-adjust:before{content:"\e063";}
.glyphicon-tint:before{content:"\e064";}
.glyphicon-edit:before{content:"\e065";}
.glyphicon-share:before{content:"\e066";}
.glyphicon-check:before{content:"\e067";}
.glyphicon-move:before{content:"\e068";}
.glyphicon-step-backward:before{content:"\e069";}
.glyphicon-fast-backward:before{content:"\e070";}
.glyphicon-backward:before{content:"\e071";}
.glyphicon-play:before{content:"\e072";}
.glyphicon-pause:before{content:"\e073";}
.glyphicon-stop:before{content:"\e074";}
.glyphicon-forward:before{content:"\e075";}
.glyphicon-fast-forward:before{content:"\e076";}
.glyphicon-step-forward:before{content:"\e077";}
.glyphicon-eject:before{content:"\e078";}
.glyphicon-chevron-left:before{content:"\e079";}
.glyphicon-chevron-right:before{content:"\e080";}
.glyphicon-plus-sign:before{content:"\e081";}
.glyphicon-minus-sign:before{content:"\e082";}
.glyphicon-remove-sign:before{content:"\e083";}
.glyphicon-ok-sign:before{content:"\e084";}
.glyphicon-question-sign:before{content:"\e085";}
.glyphicon-info-sign:before{content:"\e086";}
.glyphicon-screenshot:before{content:"\e087";}
.glyphicon-remove-circle:before{content:"\e088";}
.glyphicon-ok-circle:before{content:"\e089";}
.glyphicon-ban-circle:before{content:"\e090";}
.glyphicon-arrow-left:before{content:"\e091";}
.glyphicon-arrow-right:before{content:"\e092";}
.glyphicon-arrow-up:before{content:"\e093";}
.glyphicon-arrow-down:before{content:"\e094";}
.glyphicon-share-alt:before{content:"\e095";}
.glyphicon-resize-full:before{content:"\e096";}
.glyphicon-resize-small:before{content:"\e097";}
.glyphicon-exclamation-sign:before{content:"\e101";}
.glyphicon-gift:before{content:"\e102";}
.glyphicon-leaf:before{content:"\e103";}
.glyphicon-eye-open:before{content:"\e105";}
.glyphicon-eye-close:before{content:"\e106";}
.glyphicon-warning-sign:before{content:"\e107";}
.glyphicon-plane:before{content:"\e108";}
.glyphicon-random:before{content:"\e110";}
.glyphicon-comment:before{content:"\e111";}
.glyphicon-magnet:before{content:"\e112";}
.glyphicon-chevron-up:before{content:"\e113";}
.glyphicon-chevron-down:before{content:"\e114";}
.glyphicon-retweet:before{content:"\e115";}
.glyphicon-shopping-cart:before{content:"\e116";}
.glyphicon-folder-close:before{content:"\e117";}
.glyphicon-folder-open:before{content:"\e118";}
.glyphicon-resize-vertical:before{content:"\e119";}
.glyphicon-resize-horizontal:before{content:"\e120";}
.glyphicon-hdd:before{content:"\e121";}
.glyphicon-bullhorn:before{content:"\e122";}
.glyphicon-certificate:before{content:"\e124";}
.glyphicon-thumbs-up:before{content:"\e125";}
.glyphicon-thumbs-down:before{content:"\e126";}
.glyphicon-hand-right:before{content:"\e127";}
.glyphicon-hand-left:before{content:"\e128";}
.glyphicon-hand-up:before{content:"\e129";}
.glyphicon-hand-down:before{content:"\e130";}
.glyphicon-circle-arrow-right:before{content:"\e131";}
.glyphicon-circle-arrow-left:before{content:"\e132";}
.glyphicon-circle-arrow-up:before{content:"\e133";}
.glyphicon-circle-arrow-down:before{content:"\e134";}
.glyphicon-globe:before{content:"\e135";}
.glyphicon-tasks:before{content:"\e137";}
.glyphicon-filter:before{content:"\e138";}
.glyphicon-fullscreen:before{content:"\e140";}
.glyphicon-dashboard:before{content:"\e141";}
.glyphicon-heart-empty:before{content:"\e143";}
.glyphicon-link:before{content:"\e144";}
.glyphicon-phone:before{content:"\e145";}
.glyphicon-usd:before{content:"\e148";}
.glyphicon-gbp:before{content:"\e149";}
.glyphicon-sort:before{content:"\e150";}
.glyphicon-sort-by-alphabet:before{content:"\e151";}
.glyphicon-sort-by-alphabet-alt:before{content:"\e152";}
.glyphicon-sort-by-order:before{content:"\e153";}
.glyphicon-sort-by-order-alt:before{content:"\e154";}
.glyphicon-sort-by-attributes:before{content:"\e155";}
.glyphicon-sort-by-attributes-alt:before{content:"\e156";}
.glyphicon-unchecked:before{content:"\e157";}
.glyphicon-expand:before{content:"\e158";}
.glyphicon-collapse-down:before{content:"\e159";}
.glyphicon-collapse-up:before{content:"\e160";}
.glyphicon-log-in:before{content:"\e161";}
.glyphicon-flash:before{content:"\e162";}
.glyphicon-log-out:before{content:"\e163";}
.glyphicon-new-window:before{content:"\e164";}
.glyphicon-record:before{content:"\e165";}
.glyphicon-save:before{content:"\e166";}
.glyphicon-open:before{content:"\e167";}
.glyphicon-saved:before{content:"\e168";}
.glyphicon-import:before{content:"\e169";}
.glyphicon-export:before{content:"\e170";}
.glyphicon-send:before{content:"\e171";}
.glyphicon-floppy-disk:before{content:"\e172";}
.glyphicon-floppy-saved:before{content:"\e173";}
.glyphicon-floppy-remove:before{content:"\e174";}
.glyphicon-floppy-save:before{content:"\e175";}
.glyphicon-floppy-open:before{content:"\e176";}
.glyphicon-credit-card:before{content:"\e177";}
.glyphicon-transfer:before{content:"\e178";}
.glyphicon-cutlery:before{content:"\e179";}
.glyphicon-header:before{content:"\e180";}
.glyphicon-compressed:before{content:"\e181";}
.glyphicon-earphone:before{content:"\e182";}
.glyphicon-phone-alt:before{content:"\e183";}
.glyphicon-tower:before{content:"\e184";}
.glyphicon-stats:before{content:"\e185";}
.glyphicon-sd-video:before{content:"\e186";}
.glyphicon-hd-video:before{content:"\e187";}
.glyphicon-subtitles:before{content:"\e188";}
.glyphicon-sound-stereo:before{content:"\e189";}
.glyphicon-sound-dolby:before{content:"\e190";}
.glyphicon-sound-5-1:before{content:"\e191";}
.glyphicon-sound-6-1:before{content:"\e192";}
.glyphicon-sound-7-1:before{content:"\e193";}
.glyphicon-copyright-mark:before{content:"\e194";}
.glyphicon-registration-mark:before{content:"\e195";}
.glyphicon-cloud-download:before{content:"\e197";}
.glyphicon-cloud-upload:before{content:"\e198";}
.glyphicon-tree-conifer:before{content:"\e199";}
.glyphicon-tree-deciduous:before{content:"\e200";}
.glyphicon-briefcase:before{content:"\1f4bc";}
.glyphicon-calendar:before{content:"\1f4c5";}
.glyphicon-pushpin:before{content:"\1f4cc";}
.glyphicon-paperclip:before{content:"\1f4ce";}
.glyphicon-camera:before{content:"\1f4f7";}
.glyphicon-lock:before{content:"\1f512";}
.glyphicon-bell:before{content:"\1f514";}
.glyphicon-bookmark:before{content:"\1f516";}
.glyphicon-fire:before{content:"\1f525";}
.glyphicon-wrench:before{content:"\1f527";}
它尚未随Bootstrap 4一起提供,但现在Bootstrap团队正在开发其图标库。
对于正在寻找一线解决方案的人,您只能导入Bootstrap Glyphicons:
<link href="https://stackoverflow.com//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" type="text/css" rel="stylesheet">
概述:
我正在使用没有字形图标的bootstrap 4。我发现了依赖于字形的引导树视图存在问题。我按原样使用treeview,并且我使用scss @extend将图标类样式转换为真棒字体样式。我觉得这很漂亮(如果您问我的话)!
细节:
我用scss @extend替我处理。
我以前决定使用font-awesome的原因没有比过去使用过的更好。
当我尝试引导树视图时,我发现图标丢失了,因为我没有安装字形图标。
我决定使用scss @extend功能,以使glyphicon类像这样使用font-awesome类:
.treeview {
.glyphicon {
@extend .fa;
}
.glyphicon-minus {
@extend .fa-minus;
}
.glyphicon-plus {
@extend .fa-plus;
}
}
如果您使用的是Laravel 5.6,则它随Bootstrap 4一起提供。您需要做的是:
npm install and npm install open-iconic --save
在/resources/assets/sass/app.scss
变化的线谷歌字体,2号线进口
@import '~open-iconic/font/css/open-iconic-bootstrap';
您现在要做的就是
npm run watch
并包括
<link rel="stylesheet" href="{{asset('css/app.css')}}">
在主刀片文件顶部并且<script src="{{asset('js/app.js')}}"></script>
在关闭body标签之前。您将获得Bootstrap 4和图标。
用法是 <span class="oi oi-cog"></span>
请参阅此处以获取图标详细信息:打开图标:由Bootstrap 4推荐
如果在Laravel以外的其他项目上,则只需将其导入@import 'node_modules/open-iconic/font/css/open-iconic-bootstrap-min.css';
样式文件即可。
希望这可以帮助。尝试愉快。
去
https://github.com/Darkseal/bootstrap4-glyphicons
下载并包含在您的代码中
<link href="bootstrap4-glyphicons/css/bootstrap-glyphicons.css" rel="stylesheet">