Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Website styling not being applied. (Calling stylesheet.css from a php include)

Tags:

css

php

web

I wonder whether anyone could help me resolve some problems I'm having in creating a website using HTML, CSS...and PHP for the first time. (My previous attempts at web design were only in HTML and CSS).

The problem at present is that my home-page (index.php) somehow isn't 'seeing' my stylesheet.css.

The code for the index.php is basically as follows :

    <?php
      $page_title='Home';
      [php-code here, to call in include1.php.....Please see below for details]
    ?>
    <div class="copy">
      [page content here, in html]
    </div>
   <?php
      [php-code here, to call in include2.php.....Please see below for details]
?>

My folder structure is : web

   css
     stylesheet.css
   images
     logo.png
   includes
     include1.php
     include2.php
   index.php

In attempting to call in include1.php (containing doc type declaration, and Head section including reference to stylesheet.css), I've tried the following (inserted between <?php and ?>, as shown above), all without success :

$pathtoinclude1 = $_SERVER]'DOCUMENT_ROOT'];
$pathtoinclude1 .= "/includes/include1.php";
include_once($pathtoinclude1);

and

include('/includes/include1.php')

In include1.php, my reference to the stylesheet.css is :

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

When I preview the home-page, all I get is the text in default font (Times New Roman?). None of the styling via CSS is being applied.

Can anyone give me some pointers as to what I'm doing wrong?

like image 815
alhas2009 Avatar asked Dec 21 '25 17:12

alhas2009


1 Answers

If that first answer doesn't work, try replacing

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

with <?php include 'style.php'?>

And then in the style.php file include the <style> tags and then add the css regularly.

like image 61
CFl Avatar answered Dec 24 '25 06:12

CFl



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!