Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: Width 100% is not 100% of Screen

Tags:

css

On my sandbox site there is a white bar across the top. It is contained within the body(which has the background image), and the navbars styles are

#topnav4 {background: #fff;  width: 100%; height: 70px;  }

But the bar doesn't reach the edges of the screen. Furthermore, I don`t have any margins or padding set. does anyone know how to fix this?

Update, also note that the navbar is not at the very top of the screen. There is space between the top of the navbar and the top of the page. How do I get rid of this?

Update, I added this code but the problem is still not fixed

#topnav4 {background: #fff; position: absolute; left: 0px; top: 0px; width: 100%; height: 70px; }

like image 266
mjmitche Avatar asked Nov 27 '22 22:11

mjmitche


2 Answers

The snippet you're looking for is:

html, body {
    margin: 0;
    padding: 0;
}

That will remove the default user agent "page margins" in all browsers.

Remove your position: absolute-based additions - that's not the optimal way to solve this problem.

like image 175
thirtydot Avatar answered Dec 08 '22 00:12

thirtydot


You probably need to set the margin and padding of your body to 0.

body {
    margin: 0;
    padding: 0;
}
like image 21
rolling stone Avatar answered Dec 08 '22 01:12

rolling stone