我的index.php调用在页面加载期间插入一个html部分:
的index.php:
<html>
<head>
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<!-- navigation -->
<?php include 'navigation.html'; ?>
</body>
</html>
navigation.html:
<div>
<p class="paragraph-inline">Welcome to the amazing navigation system!</p>
</div>
好吧,这是一个简单的例子,问题的关键在于,导航器在插入页面之前完全呈现。这意味着没有调用css,只有在html blob中包含css时才能调用css。
我不希望将css包含在每个blob中(页脚,标题等)
那么如何强制网站加载html并在之后应用样式呢?我只想在主页顶部有一个css链接。
答案 0 :(得分:2)
您的导航也应该是.php。我不确定语法是否有选项,但我这样写<?php include("whatever-partial.php"); ?>
这对我来说从来都不是问题。我通常用无聊的东西制作一个head.php,然后将其包含在header.php中 - 然后是index.php - 例如,它引入了header.php和footer.php。服务器读取所有php - 并吐出一个提供给浏览器的html页面并应用样式。这不是动态的。
答案 1 :(得分:1)
确保您的include是一个php文件 - 然后在浏览器获取页面并呈现css之前将其插入页面。应该很简单。