Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a header.php and footer.php with CSS files?

I am building my site using HTML files. I would like my header and footer to be dynamic so that I can easily update anything... verses updating 10+ files every time. I'm not familiar with creating a .php file for this use.

I've researched and tried a few ways to do this... but it's not working...I know I'm doing this wrong. haha...

I do not want to make my index.html into index.php. Is there an easier way to do this?

like image 510
Maxine Avatar asked May 14 '26 13:05

Maxine


1 Answers

If you absolutely can't make your index a php file. Then, you can always make an ajax request to get the header and footer. However, it is very simple to have a dynamic header and footer with php.

The index

<!DOCTYPE html>
<html>
   <head>
       <link rel="stylesheet" type="text/css" href="style.css">
   </head>
   <body>
       <?php include 'header.html'; ?>
       <?php include 'footer.html'; ?>
   </body>
</html>

The header.html file

<header>
    <p>Some stuff in my header...</p>
</header>

The footer.html file

<footer>
    <p>Some stuff in your footer</p>
</footer>

The style.css file

header {
    /* My styles here */
}

footer {
    /* My styles here */
}

Hope this helps you.

like image 129
Jacob Avatar answered May 16 '26 02:05

Jacob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!