Подтвердить что ты не робот

Bootstrap 4 - миграция глификонов?

У нас есть проект, который интенсивно использует глификоны. Bootstrap v4 полностью отбрасывает шрифт глификона.

Есть ли эквивалент для значков, поставляемых с Bootstrap V4?

Список изменений

http://v4-alpha.getbootstrap.com/migration/

4b9b3361

Ответ 1

Вы можете использовать Font Awesome и Github Octicons в качестве бесплатной альтернативы для Glyphicons.

Bootstrap 4 также переключился с Less на Sass, так что вы можете интегрировать шрифт Sass (SCSS) в процесс сборки, чтобы создать единый файл CSS для ваших проектов.

Также смотрите https://getbootstrap.com/docs/4.1/getting-started/build-tools/, чтобы узнать, как настроить инструмент:

  1. Загрузите и установите Node, который мы используем для управления нашими зависимостями.
  2. Перейдите в каталог root /bootstrap и запустите npm install чтобы установить наши локальные зависимости, перечисленные в package.json.
  3. Установите Ruby, установите Bundler с помощью gem install bundler и, наконец, запустите bundle install. Это установит все зависимости Ruby, такие как Jekyll и плагины.

Font Awesome

  1. Загрузите файлы по адресу https://github.com/FortAwesome/Font-Awesome/tree/fa-4
  2. Скопируйте папку font-awesome/scss папку /bootstrap
  3. Откройте файл SCSS /bootstrap/bootstrap.scss и запишите следующий код SCSS в конце этого файла:

    $fa-font-path: "../fonts"; @import "../font-awesome/scss/font-awesome.scss";

  4. Обратите внимание, что вам также нужно скопировать файл шрифта из font-awesome/fonts в dist/fonts или любую другую общую папку, установленную $fa-font-path на предыдущем шаге

  5. Запустите: npm run dist чтобы перекомпилировать ваш код с помощью Font-Awesome

Github Octicons

  1. Загрузите файлы по адресу https://github.com/github/octicons/.
  2. Скопируйте папку octicons в вашу папку /bootstrap
  3. Откройте файл SCSS /bootstrap/bootstrap.scss и запишите следующий код SCSS в конце этого файла:

    $fa-font-path: "../fonts"; @import "../octicons/octicons/octicons.scss";

  4. Обратите внимание, что вам также нужно скопировать файл шрифта из font-awesome/fonts в dist/fonts или любую другую общую папку, установленную $fa-font-path на предыдущем шаге

  5. Запустите: npm run dist чтобы перекомпилировать ваш код с помощью Octicons

Glyphicons

На сайте Bootstrap вы можете прочитать:

Включает в себя более 250 глифов в формате шрифта из набора Glyphicon Halflings. Глификоны Халфлингов, как правило, не доступны бесплатно, но их создатель сделал их доступными для Bootstrap бесплатно. В качестве благодарности, мы просим вас только включить ссылку на Glyphicons, когда это возможно.

Как я понимаю, вы можете использовать эти 250 символов бесплатно для Bootstrap, но не ограничиваясь только версией 3. Таким образом, вы можете использовать их для Bootstrap 4 тоже.

  1. Скопируйте файлы шрифтов с: https://github.com/twbs/bootstrap-sass/tree/master/assets/fonts/bootstrap
  2. Скопируйте файл https://github.com/twbs/bootstrap-sass/blob/master/assets/stylesheets/bootstrap/_glyphicons.scss в свою папку bootstrap/scss
  3. Откройте файл scss/bootstrap/bootstrap.scss и запишите следующий код SCSS в конце этого файла:
$bootstrap-sass-asset-helper: false;
$icon-font-name: 'glyphicons-halflings-regular';
$icon-font-svg-id: 'glyphicons_halflingsregular';
$icon-font-path: '../fonts/';
@import "glyphicons";
  1. Запустите: npm run dist чтобы перекомпилировать ваш код с Glyphicons.

Обратите внимание, что для компоновки Bootstrap 4 требуется постопрефиксатор CSS. Когда вы используете статический компилятор 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-запрос. В качестве альтернативы вы также можете загрузить шрифт Font-Awesome из CDN, что может быть слишком быстрым во многих ситуациях. Оба шрифта в 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 для тестирования Bootstrap 4 с Font Awesome или Github Octicons.

Ответ 2

Миграция с Glyphicons на Font Awesome довольно проста.

Включите ссылку на шрифт 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 одинаковы. Некоторые из них изменились, поэтому вы должны их вручную исправить.

Ответ 3

Файл glyphicons.less из Bootstrap 3 доступен на 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="/Content/glyphicons.css" rel="stylesheet" />

Вам также понадобятся шрифты Glyphicon, входящие в пакет Bootstrap 3, поместите их в каталог /fonts/.

Теперь вы можете просто продолжать использовать Glyphicons с Bootstrap 4 как обычно.

Ответ 4

Если нужны только классы глификона в CSS:

@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";}

Ответ 5

Для людей, которые ищут однострочные решения, вы можете импортировать только Bootstrap Glyphicons:

<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css" rel="stylesheet">

Ответ 6

Обзор:

Я использую bootstrap 4 без глификонов. Я нашел проблему с деревом bootstrap, которое зависит от глификонов. Я использую treeview как есть, и я использую scss @extend для перевода стилей класса значков шрифтов в классные стили классов. Я думаю, что это довольно скользкий (если вы спросите меня)!

Подробности:

Я использовал scss @extend, чтобы обработать его для меня.

Я ранее решил использовать шрифт-awesome по лучшей причине, чем я использовал его в прошлом.

Когда я пошел, чтобы попробовать bootstrap treeview, я обнаружил, что значки отсутствовали, потому что у меня не было установленных глифов.

Я решил использовать функцию scss @extend, чтобы классы глификона использовали класс-awesome-классы так:

.treeview {
  .glyphicon {
    @extend .fa;
  }
  .glyphicon-minus {
    @extend .fa-minus;
  }
  .glyphicon-plus {
    @extend .fa-plus;
  }
}

Ответ 7

Если вы используете Laravel 5.6, он поставляется с Bootstrap 4. Все, что вам нужно, это:

npm install and npm install open-iconic --save

В /resources/assets/sass/app.scss измените строку импорта шрифтов Google в строке 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>

См. Здесь информацию о значке: Open Iconic: Рекомендован Bootstrap 4

Если в другом проекте, кроме Laravel, вы можете просто импортировать @import 'node_modules/open-iconic/font/css/open-iconic-bootstrap-min.css'; в вашем файле стиля.

Надеюсь это поможет. Счастливые попытки.