Welcome Guest, Not a member yet? Register   Sign In
[Solved] Content from <Head> is inserted in <Body>. Why?
#1

[eluser]Zefirs[/eluser]
Hello, I hope you guys could help me (newbie), I have this weird problem.

Here is the example view.php code->
Code:
<html>
<head>
<link rel="stylesheet" type="text/css" href="/css/test.css" />
</head>
<body>
This is content!
</body>
</html>

When I inspect element in Firefox or Chrome or .. code is ->

Code:
<html>
<head>

</head>
<body>
<link rel="stylesheet" type="text/css" href="/css/test.css" />
body{
color:red;
} </link>
This is content!
</body>
</html>

Why link or script parts are transfered in <body>? Only meta tag stays in head
tag..

Solution! The cause - Im using notepad++ , default encoding is ASNI, but I needed UTF-8,I realized that when half php file was written already. I converted it to UTF-8, and then it happened. CSS from <HEAD> jumped in <BODY>, and other crazy things started.

Do not convert encoding in Notepad++ if file is containing any information, use other editor than notepad++ to convert encodings ANSI -> UTF-8.


Sorry for my bad English.
#2

[eluser]RedIgniter[/eluser]
I don't know if this may be the problem but try inserting title in your head tags by doing

Code:
<html>
<head>
<link rel="stylesheet" type="text/css" href="/css/test.css" />
<title>Your page title</title>
</head>

<body>
Your body content.
</body>
</html>
#3

[eluser]talldarkmystere[/eluser]
If you're including your head as part of a sub-view that is then included in another template, be sure that you're using the TRUE flag to tell CI that it needs to process the sub template before passing it to the main one.


Code:
$headerdata['title'] = 'My Page Title';
$headerdata['css'] = 'mycssfile.css';

$data['head_content'] = $this->load->view('head_sub_template', $headerdata, TRUE);

$this->load->view('body_template', $data);

Without the TRUE flag, the content will still be passed, but it will be thrown into the top of the page.
#4

[eluser]Zefirs[/eluser]
I have no templates, only one view. Problem is that only link and meta tags are somehow inserted in wrong place.
#5

[eluser]talldarkmystere[/eluser]
Did you try adding a new line between the <head> and <body> tags as suggested above?

Is this a common problem with all pages served, or just CI backed ones?

Also: You say that you're inspecting the element - Are you just viewing the source, or using a tool for inspecting elements? Sometimes tools like that can monkey with the code. See if you get the same problem just viewing your source.
#6

[eluser]Zefirs[/eluser]
I added new line - no changes.

Problem is only with CI backed ones..

Inspecting element with chrome default element inspecting tool, and in firefox with firebug plugin.

Source code is correct in all browsers, but when I inspect element it shows me this problem.

Im using wampserver 2 and newest CI. Sent my friend the CI to test, he had the same issue.
#7

[eluser]talldarkmystere[/eluser]
So long as this does not effect regular source viewing, or page generation in the browser, I'd say just chalk it up as an oddity in the DOM inspector. In other words, nothing to worry about.

I found it odd that it appeared to include the contents of the css file as well as placing it in the 'wrong' place - I have a feeling that it's showing you the source that's been interpreted by the browser in some funny way.
#8

[eluser]InsiteFX[/eluser]
Maybe you need a DOCTYPE!

InsiteFX
#9

[eluser]talldarkmystere[/eluser]
[quote author="InsiteFX" date="1295664539"]Maybe you need a DOCTYPE!

InsiteFX[/quote]


Good idea, that. That could effect the results!
#10

[eluser]talldarkmystere[/eluser]
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;link rel="stylesheet" type="text/css" href="/css/test.css" /&gt;
&lt;/head&gt;
&lt;body&gt;
This is content!
&lt;/body&gt;
&lt;/html&gt;




Theme © iAndrew 2016 - Forum software by © MyBB