Include creates space in Site Layout

Asked

Viewed 1,162 times

1

I have two pages. One index.php and the other is called menu.php.

As the menu is the same and I repeat it on several pages I preferred to do it in a separate document and then add it with the include ("menu.php"). Only every time I use it there’s a space, like in the following picture.

inserir a descrição da imagem aqui

And if I add more include space repeats itself, see:

inserir a descrição da imagem aqui

When I look at the source code " " I don’t even know where it came from.

inserir a descrição da imagem aqui

I could insert the excerpt from the code here however this problem I only have when I use include, now if I assemble the whole structure of index.php in the same page this problem does not happen.

index.php page code

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<!-- Meta Tags -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<!-- Scripts -->
    <title>Home</title>
</head>
    <body>

        <!-- Google analitycs -->
        <?php include_once("includes/analyticstracking.php") ?>

        <!-- Menu -->
        <?php include_once("includes/menu.php") ?>

    </body>
</html>

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

menu code.php

<div class="men">

</div>

code of the general.css

@charset "utf-8";
/* CSS Document */

/* Padrão Geral */
@font-face {font-family: NFO;font-style: normal; font-weight: normal; src: url(../fonte/fonte.woff); }
a{text-decoration:none; color:inherit}
*{font-family:NFO; margin:0px; padding:0px  }
body{background-color:#f4f4f4}

/* Pagina Index */

    /* Menu */
        .men{width:100%; height:60px; background-color:#2f2f2f; float:left}
  • I tested here and this normal. it may be some apache configuration.

  • 1

    I read about the problem. The problem is that depending on the operating system, by including a php file in another php file, the file itself creates invisible characters, and these characters are interpreted by the browser generating this space in the layout. As soon as I find an answer that’s really useful I’ll post it here.

  • Have you tried your CSS code: html,body {margin:0;padding:0;} and see the results?

  • You could provide the full code of the.php menu and analyticstracking.php ?

  • Man, this question deserves all the credit, because a lot of people have broken their heads with this.

2 answers

5


This type of problem also happens because of the codification of documents.

Try opening the files used with Notepad++ and convert to UTF-8 NO GOOD, choosing the option below

Selecione "Converter para UTF-8(sem BOM)

Just click on the "Format" tab to open this option

  • rssrrsrs, When I gave that answer, I had no idea it would be so useful! But it is a similar problem that happened to me (I broke my head a lot!)

1

I found the answer in English in this link here: https://stackoverflow.com/questions/10549445/utf8-without-bom-encoding-in-eclipse

I found it easier to use Edit->Encoding Set. Set it to ISO, delete the characters, save, set it back to UTF-8. No need to close and reopen the file

When setting the encoding to ISO some characters appear at the very beginning of the page. Just delete them and set it back to UTF-8.

Facilitates for those who use eclipse, worked perfectly with me.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.