简体   繁体   中英

How to include css in html using php

I'm including css using php like

<?php include "css/cssnew.css"; ?>

But Font Awesome not working, icons showing as squares

css:

@font-face {
    font-family: FontAwesome;
    src: url(/css/fonts/fontawesome-webfont);
    font-weight: 400;
    font-style: normal
}

.fa {
    display: inline-block;
    font: normal normal normal 14px/1 FontAwesome;
    font-size: inherit;
    text-rendering: auto;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale
}

.fa-angle-double-up:before {
    content: '\f102';
}

Can anyone please tell me why that fa-angle-double-up:before is not showing

        content: '\f102';

I know, there are 3 method for adding CSS to HTML and echo with PHP:

  1. Use link:

<?php echo '<link rel="stylesheet" type="text/css" href="style.css" media="screen" />';

In this method, you can add your CSS codes in CSS file style.css and echo HTML <link> with PHP.

  1. Embedding CSS into the HTML:

<?php echo '<style media="screen" type="text/css">Add style rules here</style>'; ?>

Example:

<?php echo '<style media="screen" type="text/css">@font-face{font-family:FontAwesome;src:url(/css/fonts/fontawesome-webfont);font-weight:400;font-style:normal}.fa{display:inline-block;font:normal normal normal 14px/1 FontAwesome;font-size:inherit;text-rendering:auto;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.fa-angle-double-up:before{content:"\f102"}</style>'; ?>
  1. Last method:

<style><?php include "css/cssnew.css"; ?></style>

Or

<?php 
echo '<style>'; 
include "css/cssnew.css"; 
echo '</style>'
;?>

You have to use CSS with tag.

<style>
    <?php 
         include 'css/cssnew.css'; 
    ?>
</style>

you can also use HTML tag.

<?php
echo '<link href="css/cssnew.css" rel="stylesheet">';
?>

As your comment says, You can save below php code as newcss.php

<?php echo '<link href="css/cssnew.css" rel="stylesheet">'; ?>

Now dynamically include in your PHP file as

<?php 
         include 'newcss.php'; 
?>

Try like below

Inside HTML

<link rel="stylesheet" href="css/cssnew.css" type="text/css">

Inside Php

<?php echo '<link href="css/cssnew.css" rel="stylesheet" type="text/css" >'; ?>

Well I saw this two options. I hope it helps.

 <?php echo '<link href="bootstrap/css/bootstrap-responsive.css" rel="stylesheet">'; ?> <!-- or --> <style><? include_once ”PATH/your_style.css" media ="" ?></style> // <style><? require_once ”PATH/your_style.css" media ="" ?></style> <!--Good Luck I hope it helps!--> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM