I have googled a lot but it seems that I am doing something wrong.
I want to do this:
<?php include 'header.php'; include'CSS/main.css'; ... ?>
However, my page prints the CSS code.
Note: I want to use PHP to include the CSS file, and not use I also do you want to rename my CSS file to a PHP file as some website mentioned.
Any clues?
Many thanks.
Though you can output CSS to interact with your HTML, using PHP. Using CSS with PHP is even more simple that you might think. Similar to echoing out a text string in PHP, CSS is echoed out the same way. You can use CSS echoed out through PHP just like you would in HTML.
Note: There are two different ways to import a CSS file into another using @import url(“style2. css”); or @import “style2. css”; or directly import any CSS file or multiple CSS file in the HTML file directly within <style>@import “style1.
CSS represents the style and the appearance of content like font, color, margin, padding, etc. PHP is used for server-side programming which will interact with databases to retrieve information, storing, email sending, and provides content to HTML pages to display on the screen.
You have to surround the CSS with a <style>
tag:
<?php include 'header.php'; ?> <style> <?php include 'CSS/main.css'; ?> </style> ...
PHP include
works fine with .css
ending too. In this way you can even use PHP in your CSS file. That can be really helpful to organize e.g. colors as variables.
You are including the CSS code as text in your PHP page. Why not just link it in the traditional fashion?
<link rel="stylesheet" href="CSS/main.css" type="text/css">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With