0

I am trying to make the top border of the nav div to cover the entire screen but it is not working.

body {
  line-height: 1; 
  width: 1020px;
  font-family: 'Droid Sans', sans-serif;
  margin: 0 auto; 
}

.nav {
  margin: 0 auto; 
  border-top: 6px solid #9FCC7F; 
  width: 100vw;
}
<body>
  <div class="nav"></div><!-- Nav --> 
</body>

It is strange that the view port function is not working? Would you mind taking a look?

enter image description here

thanks again.

prasanth
  • 22,145
  • 4
  • 29
  • 53
danish deb
  • 111
  • 8

5 Answers5

0

change the width: 100vw to width 100% and it should work

Take a look at this: Difference between Width:100% and width:100vw?

Community
  • 1
  • 1
weinde
  • 1,074
  • 3
  • 13
  • 32
0

body {
  line-height: 1;
  font-family: 'Droid Sans', sans-serif;
  margin: 0 auto; 
}

.nav {
  margin: 0 auto; 
  border-top: 6px solid #9FCC7F;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<body>
  <div class="nav"></div><!-- Nav --> 
</body>
0

It may be because, the body width 1020px you mentioned exceeds the resolution that a device can support,

Check this link : http://www.w3schools.com/css/css_rwd_viewport.asp

So viewport cannot render correctly when the fixed width exceeds maximum resolution of the device

Set the property as

body{
 width:100%; // for full page width
}

else

leave the width, the browser automatically detects it

0

Removing width:1020px from body solves your problem.

Here's an example https://jsfiddle.net/rahulxdd/wc5c0xk1/

    body {
          width: 100%;
         }
Rahul
  • 493
  • 6
  • 27
0

I added the code for You : better you apply with width:100% because its will auto adjust with in responsive view port. px are not adapting

1020px only adapting with in desktop mode.switch with mobile,tab mode its not usefull.so only sugges with 100%

And don't forget to add viewport tag <meta name="viewport" content="width=device-width, initial-scale=1.0"> Its a auto adjust with viewport .

See Reference

body {
  width: 100%;
  font-family: 'Droid Sans', sans-serif;
  }

.nav {
  position:absolute;
  left:0;
  top:0;
  margin:0;
  padding:0;
  border-top: 6px solid #9FCC7F; 
  width: 100%;
}
<body>
  <div class="nav"></div><!-- Nav --> 
</body>
prasanth
  • 22,145
  • 4
  • 29
  • 53