背景图像100%在实例中不起作用


Background Image 100% Not Working In Instances

这适用于我的主页,使图像适合我的背景。

<body>
<div style="height:100%; background-image:url(location.png); background-size:cover;">
<?php include("homebuttons.php");?>
</div>
</body>

但似乎不想在这个工作

<body>
<div style="height:100%; background-image:url(location.png); background-size:cover;">
<div class="navbar">
<?php include("navbar.php"); ?>
</div>
<div id="content">
<?php include("pages/" . $_POST["var"] . ".php"); ?>
</div></div>
</body>

我试过将DIV定位在不同的位置,但仍然一无所获。我所需要的只是某个页面的背景。我计划在完成后使用此代码。

<div style="height:100%; background-image:url(<?php echo $_POST["var"] ?>.jpg); background-size:cover;">

问题是style="height:100%;在div中,当您定义height:100%时,这100%指的是元素父级大小,而不是视口大小。这只适用于宽度,您需要用px大小设置最小高度才能实现。

由于某些原因,当您有时

<!DOCTYPE html>

在文档中,这种100%匹配将不起作用。奇怪的