FridgeProduction
FridgeProduction

Reputation: 11

CSS/(PHP/HTML?) Background

For my site I've been trying to get the background to WORK and to REPEAT, but there's something wrong I guess? This is my code:

    body
{
    background-image:url('../images/backkground.png');
}

and then it's included in the index like this:

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

Yeah I know, those php tags but that's placed before all the rest. Does anyone have tips on what I'm doing wrong? (If I AM doing something wrong)

Upvotes: 0

Views: 60

Answers (3)

Jay Blanchard
Jay Blanchard

Reputation: 34416

You don't use PHP to include a CSS file, you reference it in HTML:

 <link rel="stylesheet" href="/path/to/style.css" type="text/css">

Ideally you place this in the <head></head> tags at the top of the HTML page.

Upvotes: 3

Josejulio
Josejulio

Reputation: 1295

As the others already told you, you are using the include in the server side, you should use something like

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

But if for any reason you need to use the server side include, you could try the following:

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

Upvotes: 0

Digital Chris
Digital Chris

Reputation: 6202

You're using PHP's include wrong. What you're doing is including the contents of the file server side.

You want to include the stylesheet in the HTML output:

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

In PHP this would look like:

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

It could also be a problem with where the file is. It should be in the same directory as the calling page so if you're on site.com/index.php you should be able the see the css file at site.com/style.css.

Upvotes: 1

Related Questions