0

I am trying to develop a website in php. On my main page I use include function (in php) to include other files in it. But when load the main page the CSS in the other files get all screwed up. It is showing as if there is no CSS at all so everything is on top of each other. When I load the files separately everything works perfectly fine.

So in the index.php file I have

//code 
include 'toolbar.php';

Then in toolbar.php I have

div.fileinputs 
{
    position: relative;
}

div.fakefile 
{
    position: absolute;
    top:0px;
    left:0px;
    z-index: 10;
}
.text_computer
{
    position: absolute;
    top:80px;
    left:20px;
    z-index: 20;
    text-align:center
}
input.file 
{
    cursor: pointer;
    position: relative;
    text-align: right;
    -moz-opacity:0 ;
    filter:alpha(opacity: 0);
    opacity: 0;
    z-index: 30;
    width:317;
    height:202;
}
.text_upload
{
    position: absolute;
    top:6px;
    left:80px;
    z-index: 20;
    text-align:center
}
input.submit
{
    cursor: pointer;
    position: relative;
    text-align: right;
    -moz-opacity:0 ;
    filter:alpha(opacity: 0);
    opacity: 0;
    z-index: 30;
    width:330;
    height:50;
}
//code
<div class="fileinputs">
            <input type="file" class="file" name='image'/>
            <div class="fakefile">
                <img src='red_frame.png' width='330'>
            </div>
            <div class="text_computer">
                <a style='font-family:Arial;color:white;'><font size='6'>Choose a photo from<br> your Computer</font></a>
            </div>
        </div>
        <div class="des_box">
            <textarea name='description' cols='38' rows='4' placeholder='Enter a description here...' maxlength='500'></textarea><br>
        </div>
        <br>
        <div class="fileinputs">
            <input type="submit" class="submit" value='Upload'>
            <div class="fakefile">
                <img src='red_frame.png' width='330' height='50'>
            </div>
            <div class="text_upload">
                <a style='font-family:Arial;color:white;'><font size='6'>UPLOAD!!!!</font></a>
            </div>
        </div>

This isn't all of the code but this is the part that is piling on top of each other when I include it in index.php

When I just run toolbar.php everything is spaced out fine.

Is there a way to fix this?

Could there be some other sort of problem that is causing this?

Wait never mind i found this <!DOCTYPE html> at the top of my index.php and removed it to see if it would fix the problem and for some reason it did. I have no idea why that fixed it, but now everything works.

7
  • 4
    use absolute css paths. Commented Aug 16, 2013 at 5:05
  • 3
    A working code would be helpful. Commented Aug 16, 2013 at 5:06
  • Please include the php, one of the included files, and the css Commented Aug 16, 2013 at 5:08
  • 1
    You need to provide some code examples here. Commented Aug 16, 2013 at 5:08
  • 1
    are you including the css file in php? Commented Aug 16, 2013 at 5:11

3 Answers 3

1

I suggest not to use 'include', please try in the following way-

<?php 
.
.
.
?>
<link href="../bootstrap/css/bootstrap-timepicker.min.css" rel="stylesheet" 
type="text/css"/>
<?php 
.
.
.
?>
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, I dont know what this means.
0

Just include your CSS file through PHP. Its legitimate !

<?php include ('yourheader.php'); ?>
<style>
<?php include ('main.css'); ?>
</style>

2 Comments

Not only will the CSS be not cached, it will bloat every page.
True, but it does save an http request. It sounds like a terrible idea but I wonder if its actually faster in some cases.
0

You can use @import also to load the css styles.

    @import url('/css/styles.css');
    @import url('/css/main.css');
    @import url('/css/color.css');

/* All three CSS files above will be loaded from this single document. */

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.