Adjusting the CSS for the navigation bar to make it fully cover the background with color

One of the challenges I'm facing is related to styling my webpage.

I have created an inline navigation bar, but when I attempt to change its background color, it doesn't fill the height as desired. I am interested in finding a solution that will allow me to do this without altering the size or appearance of the navigation bar.

Here are some visuals (I used background-color: green; for this):

https://i.sstatic.net/Cye9s.png

body{
  margin : 0;
  padding : 0;
  font-family : 'Arial',serif;
}

/*nav class  */
.nav {
  background-color : green;
  color: white;
  list-style : none;
  text-align : right;
  padding : 0px 0 0px 0;
}

/*A li tag in a .nav class*/
.nav > li {
  display : inline-block;
  padding-right: 50px;/*same as 0 25px 0 25px ( top left bottom right */
  font-size: 14px;
}

/*a tag inside a li tag inside a .nav class*/
.nav > li > a { 
  text-decoration : none;
  color: black;
}

/* a tag inside a li tag inside a .nav class while mouse hovering */
.nav > li > a:hover {
  color : #c1c1c1;
}

.logo {
  float : left;
  padding-left : 25px;
}

.logo > .logo-image {
  position: relative;
  bottom : 8px;
  width : 128px;
}

.banner {
  width : 100%;
  display : block;
}

.banner  > .banner-image{
  width : 100%;
  display : block ;
}
<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="utf-8>
    <title>DeckArts Graphics</title>
    <link rel="stylesheet" type="text/css" href="style.css">
  </head>

  <body>
    <ul class="nav">
      <div class="logo">
        <a class="logo-image" href="#home">
          <img src="ZE.png" >
        </a>
      </div>

      <li><a href="#Home">Home</a></li>
      <li><a href="#Gallery">Gallery</a></li>
      <li><a href="#Projects">Projects</a></li>
      <li><a href="#About">About</a></li>
    </ul>

    <div class="banner">
      <img class="banner-image" src="banner.jpg" >
    </div>
  </body>
</html>

Answer №1

Adjusting margins and adding padding to the navigation bar solves the issue.

Here are the specific changes:

  1. Replace padding : 0px 0 0px 0; with padding : 10px 0 10px 0;
  2. Include margin:0px.

See the demonstration below.

body{
  margin : 0;
  padding : 0;
  font-family : 'Arial',serif;


}
/*nav class  */
.nav {
  background-color : green;
  color: white;
  list-style : none;
  text-align : right;
  padding : 10px 0 10px 0;
  margin:0px;
}
/*A li tag in a .nav class*/
.nav > li {
  display : inline-block;
  padding-right: 50px;/*same as 0 25px 0 25px ( top left bottom right */
  font-size: 14px;



}
/*a tag inside a li tag inside a .nav class*/
.nav > li > a { 
  text-decoration : none;
  color: black;
}
/* a tag inside a li tag inside a .nav class while mouse hovering */
.nav > li > a:hover {
  color : #c1c1c1;
}
.logo {

  float : left;
  padding-left : 25px;
}
.logo > .logo-image {

  position: relative;
  bottom : 8px;
  width : 128px;
}
.banner {
  width : 100%;
  display : block;
}
.banner  > .banner-image{
  width : 100%;
  display : block ;
}
<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="utf-8">
    <title>DeckArts Graphics</title>
    <link rel="stylesheet" type="text/css" href="style.css">
  </head>

  <body>
    <ul class="nav">
      <div class="logo">
        <a class="logo-image" href="#home">
          <img  src="ZE.png" >
        </a>
      </div>

      <li><a href="#Home">Home</a></li>
      <li><a href="#Gallery">Gallery</a></li>
      <li><a href="#Projects">Projects</a></li>
      <li><a href="#About">About</a></li>
    </ul>

    <div class="banner">
      <img class="banner-image" src="banner.jpg" >
    </div>
  </body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Verify if the specified date (in string form) has already occurred or is upcoming using JavaScript

I need to determine if the start date of a given date range string (e.g. 12/20/12-12/24/12) has already passed the current date. Is there a way to achieve this using JavaScript or jQuery? ...

React: issue with updating state object property

I am encountering an issue while trying to update my state. When I check the updated state value in the console, it shows that the state value is undefined. Can someone please assist me in resolving this problem? I am utilizing the rc-time-picker to select ...

Preventing jquery from continuing its execution after an event has been successfully handled

I am experiencing an issue with a radio button that triggers a jQuery script upon clicking. The script is supposed to render a form where users can enter a comment. Everything seems to be working fine, the event is detected and the form is rendered, but wh ...

Filtering an array in Node.js using multiple terms

I am currently working with a files array that includes various text files organized in a specific format: [test/fixtureData/fixtureData2/test3.inc, test/fixtureData/fixtureData3/test5.inc, test/fixtureData/test1.inc, ,test/fixtureData/test6.ssi ,test/fix ...

Creating an AngularJs directive to alter input formatting

I am looking to achieve the following: Within my controller model, I have a date object that I want users to be able to modify. I need to provide them with two input fields - one for modifying the date and the other for modifying the time. Both input fiel ...

Incorporating text sections into a div container and adjusting the width

Currently facing an issue with the canvas element on my project. <div id="app-container"> <div id="canvas-container"> <div id="canvas"></div> </div> </div> In the CSS stylesheet, the following styles ar ...

Struggling to fetch data from the Strapi page is posing a challenge

Currently, I am facing an issue where the frontend developers on my team are unable to retrieve data from the backend that I built for them using Strapi. Even after pulling my changes from github, they continue to face difficulties accessing the data. The ...

AngularJS, NodeJS, and Mongoose Challenge in Internet Explorer 11

I am currently working on developing my website using the AngularJS framework for the front end, Node.js for the backend, and Mongoose to store data in a MongoDB database. Everything works fine in Firefox RS v.24 and Chrome - when I add a new user to the ...

Angular G-map

Hey there, I'm currently working on Angular Google Maps and facing some challenges when it comes to setting the bounds and map center. You can check out my progress at https://github.com/dylanfprice/angular-gm <gm-map gm-map-id="'infoWindows ...

Filter the ng-repeat list dynamically by triggering ng-click event

I am currently developing an application on that requires users to be able to filter a list of credit cards by clicking on filters located on the interface, such as filtering for only Amex cards or cards with no fees. Although I have successfully bound t ...

Displaying a Facebook iframe on the left side of the page

I'm struggling with positioning the Facebook iframe embed to sit on the left of the text. I want it to be aligned with the left margin, but also have the text flow beside it from the same height. Can anyone offer some guidance on how to achieve this u ...

What is the best way to line up a number and text using CSS?

Creating a basic gauge meter with min value 0 and max value 2. The current UI progress is as follows: .sc-gauge { width:200px; height:200px; margin:200px auto; } .sc-background { position:relative; height:100px; margin-bottom:10px; background-color:g ...

Facing a minor HTML syntax error while attempting to configure metatags in Ruby on Rails

I'm attempting to incorporate social tags into my site, such as Tweet count, Facebook recommendations, and their respective numbers. In the app/views/application/_ogmeta.html.erb file, I have only included one line: <meta property="og:title" cont ...

Data-api configuration for bootgrid ajax

According to the BootGrid documentation, in order to set the HTTP method to GET or enable AJAX, one must use the method and ajax attributes in JavaScript. However, the Data-API example demonstrates the use of data-url and data-ajax, leading me to conclude ...

Issue with AdminLite 2.4.0 data table functionality malfunctioning

Check out this template that I'm using. I've copied all the contents for the bower_components and dist folders, and made sure to link and require everything properly. There are no 404 errors, only status code 200. Here is a snippet of my code: ...

Creating Overlapping Textures in Three.JS: A Step-by-Step Guide

Short version: How can I create larger textures on faces with a fading effect, allowing them to overlap each other? - Currently learning three.js by attempting to replicate the game Warzone 2100. :) I'm loading a default ground texture using this c ...

Prevent bootstrap columns in a single row from adjusting their heights uniformly

After spending a good amount of time reading through various questions and attempting to solve my issue, I am finally seeking help from all of you. This is what I currently have: The code in action I am aiming for the following outcome: Desired result ...

Sharing data between app.js and client-side files in Node.js: How to do it effectively?

I have a question about passing a value from my Node.js app.js file to my client-side JavaScript file. Here is my app.js file: var express = require('express'); var app = express(); var port = process.en ...

What is the best approach for implementing a getworldposition functionality with Three.js?

Looking for a way to create a getWorldPosition function in Three.js that will return a vector? This is the code I have to obtain the World Position of an object (obj) and store it in the vector vec. obj.updateMatrixWorld(); var vec = new THREE.Vector3(); ...

Bidirectional data binding in angular 12 reactive forms

After working with angular for a while, I encountered an issue while trying to implement two-way binding. The code snippet below is where I'm facing difficulty. Since the use of [(ngModel)] has been deprecated in Angular 12 within formGroup, finding ...