How to set external custom font using css in codeigniter?

Member

by gilbert , in category: PHP Frameworks , 9 months ago

How to set external custom font using css in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by raphael_tillman , 9 months ago

@gilbert 

To set an external custom font using CSS in CodeIgniter, follow these steps:

  1. First, upload your custom font files to a folder in your CodeIgniter project directory. For example, create a folder named "fonts" in the "assets" directory and place your font files (e.g., .woff, .woff2, .ttf) inside it.
  2. In your CSS file, use the @font-face rule to specify the font family and font file paths. For example:
1
2
3
4
5
6
@font-face {
    font-family: 'CustomFont';
    src: url('path/to/fonts/CustomFont.woff2') format('woff2'),
         url('path/to/fonts/CustomFont.woff') format('woff'),
         url('path/to/fonts/CustomFont.ttf') format('truetype');
}


  1. Then, use the font-family property in your CSS rules to apply the custom font to specific elements. For example:
1
2
3
body {
    font-family: 'CustomFont', sans-serif;
}


  1. Make sure to load your CSS file in your CodeIgniter view file. You can include it using the base_url() function to get the correct path to your CSS file. For example:
1
<link rel="stylesheet" href="<?php echo base_url('assets/css/styles.css'); ?>">


  1. Lastly, make sure that your CodeIgniter project's .htaccess file allows access to the fonts folder and font files. You can add a rule like the following to allow access to the fonts directory:
1
2
3
4
5
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond $1 !^(index.php|assets|fonts|images|robots.txt)
    RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>


By following these steps, you should be able to set an external custom font using CSS in your CodeIgniter project.