0

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)

7
  • 2
    Two 'k' in background.png? Commented Dec 17, 2015 at 19:23
  • The 2 K's are righ... Commented Dec 17, 2015 at 19:25
  • The image doesn't appear. The gray background that it is now stays. Commented Dec 17, 2015 at 19:26
  • 1
    Unless the include isn't working @chris85 Commented Dec 17, 2015 at 19:27
  • 1
    Are you sure include is the right thing to use here? why not <link rel="stylesheet" href="style.css">? Commented Dec 17, 2015 at 19:27

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

4 Comments

What kind of server error? Did you place it in the head tags? Was the path in the href attribute correct?
That is caused by PHP, not HTML. Can you edit your post and give us the markup for your page? Have you looked in your error logs for the 500 reason?
@FridgeProduction, HTMLs don't give you server errors, that is for sure.
Yeah sajib, but someone said to edit the tags and remove php and change it to html (the tags)
1

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.

1 Comment

Thank you sir! This was the solution :)
0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.