0

I am having trouble with the CSS when I load a page into div.

Firefox loads CSS perfectly, but in Chrome, it does not load the CSS styles of the loaded page.

It only works when I apply style with the element, for example

<table style="left:100px;top:50%;position:fixed">

Only this way does it work in Chrome.

But this doesn't work:

<style type="text/css">
.mystyle {
    left:100px;
    top:50%;
    position:
    fixed;
}   
</style>
<table class="mystyle">

Is there a way to fix this?

5
  • 2
    you need to include the style sheet reference code Commented Nov 18, 2009 at 18:43
  • i tried it, doesnt work in chrome for a reason Commented Nov 18, 2009 at 18:50
  • It will probably help if you put the page online, so people can see and check for themselves. Commented Nov 18, 2009 at 18:53
  • And does "when i load a page into div." mean you are using AJAX to do that? Because that might be important info. Commented Nov 18, 2009 at 18:54
  • yes i am using AJAX, i should have mentioned it sorry Commented Nov 18, 2009 at 18:56

3 Answers 3

1

I'm guessing the page you are loading via AJAX has its own styles in the head of that page. While that could/should work, I suggest putting all the styles for your site in one or more external style sheets and load them at every page. When you then load HTML content in a div via AJAX, the styles will already be there and will be applied to the new content.

Putting styles in an external stylesheet is, in most cases, the best practice for a number of reasons.

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

Comments

0

Did you forget a ; on the end of fixed?

<table style="left:100px;top:50%;position:fixed;">

1 Comment

It's still a good habit to always end css rules with a semi-colon, even if not strictly necessary.
0

I would be curious to see if this:

<style type="text/css">
    .mystyle {
        left:100px;    
        top:50%;    
        position:    
        fixed;
    }

       </style>

would work if it were to be formated as:

<style type="text/css">
.mystyle 
{
   left: 100px;    
   top: 50%;    
   position: fixed;
}
</style>
<table class="mystyle">

BUT, as others suggest, I would prefer to see it in an external style sheet file and linked in that way.

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.