how do I change my header background color?

noob

I want to change the header background red along the navigation menu. however, my html/css does not work as intended. can you tell me what I did wrong? I though that header selector is the container of my topnav section. not sure why changing background-color through header style doesn't do anything. if I put the bakcground-color under the .topnav a, there will be 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>
Kaushik Andani

body {
         box-sizing: border-box;
         margin: 0;
         background-color: #4c8b41;
         }
         
         header {
           background-color: red;
           height:100px;
         }
         
         .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;    
         }
<html>
   <head>
   </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>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I change the color of my background smoothly?

How do i change the background color of my website with HTML

How could I change my WooCommerce shop page header background color?

How do I change the background color with JavaScript?

How do I change the background color of the body?

How do I change a background color in JS?

How do I change the background color in JavaScript?

How do I change my Background.Color to Gray for one row in my GridView

My header has a transparent background(?) even though I have declared a background-color, how do I fix this?

How can I change JTable's header background color?

how can I change the background color of the header using an alertDialog in flutter?

How can I change the background color of the full header in React Native

How do I get the event listener to change my css background color using javascript?

How do i change the background foreground and border color in WPF when hovering with my mouse

How do I customize the header background color, height, and text of a UITableView?

I am using php include to call my header but when I change my header background color it changes my entire site

How do i change my cardview background with a custom background?

How To Change The Header Background Color On Wordpress Website

How do I change the header color of a TabPane in SceneBuilder?

How do I programmatically change a GroupBox Header font color?

How can i change the background color of a navigation header menu bar from one color to two colors

How do I change the background color of a QtQuick Window?

How do i change input field background color based on onclick?

How do I change the background color of a tabbed page in Xamarin iOS?

How do I change the background color of a unicode symbol?

How do I change the entire background color in an RMarkdown HTML Document?

How do I change button background and text color?

How do I change the background color of a cell in Pandas?

How do I change the ripple background color on Button?