html - 相同的 CSS/HTML 不同的结果?

标签 html css space

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

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

这怎么可能?

(抱歉代码示例不好,但是网站太复杂了……)

.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>

最佳答案

只要我们没有看到包含的 php 文件中的所有代码,我们就只能猜测。 谈到 CSS,您可以尝试在您的元素中使用“重置 CSS”文件。 Reset 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;
}

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

关于html - 相同的 CSS/HTML 不同的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40920515/

相关文章:

javascript - Form 如何从 span 中获取 div 元素

html - 将渐变过度延伸到 <table> 之外

python - Django - 呈现为字符串无法加载 CSS

python - CSS 样式未正确填充

css - 在特定单元格的嵌套 flex 容器(3x3 网格)内添加覆盖 div

javascript - 单击图像时播放声音文件

html - 绝对位置不起作用( Bootstrap )

gcc - 在 GCC makefile 的目标中允许空间

css - 谁能告诉我缩略图之间的 4xp 差距是从哪里来的?

c - C中空格的转义序列是什么?