Jack Westen Jack Westen - 1 year ago 142
CSS Question

padding is not disappear in the html

enter image description here

This example based on the w3schools.

I want to attach the "nav" part to the header. The red notification part is issue. I don't know why the "nav" doesn't atteched to header. I applied the padding as 0 px. Who know solve the problem? or I misunderstand about the padding? Thank for answer.

My html source is below.

<!DOCTYPE html>
div.container {
width: 100%;
border: 1px solid gray;

header, footer {
padding: 1em;
color: white;
background-color: black;
clear: left;
text-align: center;

nav {
float: left;
max-width: 160px;
margin: 0;
padding: 0em;

nav ul {
list-style-type: none;
padding: 0;

nav ul li {
padding : 25px;
border : 1px solid gray;

nav ul a {
text-decoration: none;

article {
margin-left: 170px;
border-left: 1px solid gray;
padding: 0px;
overflow: hidden;

<div class="container">
<h1>City Gallery</h1>

<li><a href="#">London</a></li>
<li><a href="#">Paris</a></li>
<li><a href="#">Tokyo</a></li>

<p>London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.</p>
<p>Standing on the River Thames, London has beeon a major settlement for two millennia, it's history going back to its founding by the Romans, who named it Londinium.</p>

<footer>Copyright ? W3Schools.com</footer>


Answer Source

your nav is built using ul tag, which has margin property set by default

this should solve your problem:

nav ul {
    list-style-type: none;
    padding: 0;
    margin: 0;

also, keep in mind that 0 shouldn't be used with units (it's a good practice)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download