【问题标题】:Same CSS/HTML different result?相同的 CSS/HTML 不同的结果?
【发布时间】:2026-01-04 13:05:02
【问题描述】:

我有一个 HTML 文件,我总是使用相同的标题(我将它包含在每个页面的顶部) 我使用 CSS 来设置这个标题的样式...

整个机身顶部没有空间,这很好。 现在我在 index.php 的页面顶部有空间,而在contact.php 的顶部没有空间,尽管它具有 相同的标题和完全相同的 CSS 文件 在此处链接输入代码...

怎么可能?

(对不起,代码示例不好,但网站显示它很复杂......)

.body{
	margin: 0 auto;
	width:70%;
	clear: both;
}
.mainHeader img{
	width: 50%;
	height: auto;
	margin-top:0px;
	margin-bottom:20px;
	display: block;
	margin-right:auto;
	margin-left:auto;
}
//index file
<?php
include 'includes/overall/header.php'; 
?>

//contact file
<?php
include 'includes/overall/header.php'; 
?>

//header file
<html>
<head>
    <title>Website Title</title>
    <meta charset="UTF-8" >
	<link rel="stylesheet" href="css/style.css"/>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

<body class="body">
<header class="mainHeader">
	<img src="logo.png"></img>
<nav>
	<ul>
		<li class="#"><a href="index.php">home</a></li>
	    <li class="#"><a href="contact.php">contact</a></li>
	</ul>
</nav>
</header>
</body>
</html>

【问题讨论】:

  • 不看实际的源文件就无法判断。在您使用的任何浏览器中查看开发人员控制台,查看应用的填充和边距,以及相关的样式。在某处,有一些不同的东西。
  • 去掉&lt;/img&gt;,图片标签不会关闭。
  • 对不起,我不是 PHP 人,但您的标题包含 htmlheadbody 标记似乎很奇怪。我认为包含应该像部分视图。另外,不要得到隧道视野......问题可能不在于头文件或标题 CSS,而可能是 index.php 页面上的标记(如杂散字符或无效标记)或页面样式.
  • index.phpcontact.php 究竟是什么样子的?看起来你上面有一些伪代码。确保在初始标记之前没有任何空格,例如 &lt;?php (includes) ?&gt; &lt;html&gt;?&gt; &lt;html&gt; 之间的空格)与 &lt;?php (includes) ?&gt;&lt;/html&gt;。 FWIW,我会包含一个文档类型,即&lt;!DOCTYPE html&gt;

标签: html css space


【解决方案1】:

只要我们没有看到包含的 php 文件中的所有代码,我们可能只能猜测。 谈到 CSS,您可能会尝试在您的项目中使用“重置 CSS”文件。重置 CSS 是一个 CSS 代码,用于清除页面中元素的所有边距、填充等。你可以看这里http://cssreset.com/scripts/eric-meyer-reset-css/

代码在这里:

/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}

所以不妨试一试,看看效果如何。

【讨论】:

  • 感谢您的快速回复,但这对我没有多大帮助...我发现问题是,Chrome 在我的身体上制作了一个用户代理样式表...它是有线的,它只是在某些页面上......你知道如何删除正文上的用户代理样式表吗?谢谢...马吕斯
最近更新 更多