I'm facing an issue with changing the background color of the header along the navigation menu using HTML/CSS. It seems that my current code is not working as expected. I believe that the header selector should contain my topnav section, but changing the background-color through the header style doesn't have any effect. If I try to put the background-color under the .topnav a, there ends up being a gap between the floating elements.
<head>
<style>
body {
box-sizing: border-box;
margin: 0;
background-color: #4c8b41;
}
header {
background-color: red;
}
.topnav a {
float: left;
color: #f8f8f8;
text-align: center;
text-decoration: none;
padding: 10px 10px;
}
.topnav a:hover {
background-color: black;
}
#topnav-right {
float: right;
}
</style>
</head>
<body>
<header>
<div class="topnav">
<a href="#"><h2>Home</h2></a>
<a href="#"><h2><input type="text" placeholder="Search"></h2></a>
<div id="topnav-right">
<a href="#"><h2>Log In</h2></a>
<a href="#"><h2>Sign Up</h2></a>
</div>
</div>
</header>
</body>
</html>