Jebediah15 Jebediah15 - 3 months ago 10
CSS Question

Background image stays after removing tag

I am learning about webdev by designing a webpage and want the landing page to have a background image but the subsequent page not to. My

index.html
page extends the
base.html
template. I used the
body
tag to apply a background image to cover the page. But I want this removed from the
results.html
view so in the
results.html
I extend a header only view using
header.html
. And in the
header.html
layout I eliminate the
body
tag, but the background image remains somehow.

Any help for a beginner is much appreciated.

base.html

{% load staticfiles %}

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">

<title>me</title>

<!-- Bootstrap core CSS -->
<link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet">

<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="{% static 'css/ie10-viewport-bug-workaround.css' %}" rel="stylesheet">

<!-- Custom styles for this template -->
<link href="{% static 'css/cover.css' %}" rel="stylesheet">

<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="{% static 'js/ie-emulation-modes-warning.js' %}"></script>

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- Static navbar -->
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Logo</a>
</div>
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="./">About Us <span class="sr-only">(current)</span></a></li>
<li><a href="#">Log In</a></li>
<li><a href="#">Sign Up</a></li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container-fluid -->
</nav>

{% block main_content %}
{% endblock %}

<div class="mastfoot">
<div class="inner">
<p>me, 2016 | <a href="https://twitter.com/me">@me</a></p>
</div>
</div>

<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="../../dist/js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>


</body>



</html>


index.html

{% extends "search/base.html" %}

{% block main_content %}

<div class="site-wrapper">

<div class="site-wrapper-inner">

<div class="cover-container">
<div class="inner cover">
<h1 class="cover-heading"></h1>
<p class="lead col-xs-6 ">Search
<input type="text" class="form-control" placeholder="">
</p>
<p class="lead col-xs-6 ">Location
<input type="text" class="form-control" placeholder="City, State or Zipcode">
</p>
<p class="lead">
<a href="#" class="btn btn-lg btn-default">Search</a>
</p>
</div>

</div>

</div>

</div>

{% endblock %}


header.html

{% load staticfiles %}

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">

<title>me</title>

<!-- Bootstrap core CSS -->
<link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet">

<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="{% static 'css/ie10-viewport-bug-workaround.css' %}" rel="stylesheet">

<!-- Custom styles for this template -->
<link href="{% static 'css/cover.css' %}" rel="stylesheet">

<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<script src="{% static 'js/ie-emulation-modes-warning.js' %}"></script>

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>

<div>

{% block main_content %}
{% endblock %}


</div>


<div class="mastfoot">
<div class="inner">
<p>me, 2016 | <a href="https://twitter.com/me">@aptlyrated</a></p>
</div>
</div>


<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="../../dist/js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>

</html>

Answer

All Webpages need a <body> element, so you can't leave it out. There are many approaches to fix this, but they all revolve around having css that loads last on the results page that tells it to have no background image.

for demonstration purposes right before your </head> tag in header.html add the code

<style>
body {background-image: none;}
</style>
Comments