Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wierd white space between border and content

Tags:

html

css

I see whitespace between the div's border and the nav in chrome only at a specific screen size. I also see it in the fiddle so I don't have any extra code. Also same happens in the snippet, I see the white space only when I expand it to full page.

unwanted whitespace

*{
  padding: 0;
  margin: 0;
  font-size: 0;
  line-height: 0;
}
div{
  min-height: 100vh;
  border: 0.5vw solid red;
  width: 100%;
  box-sizing: border-box;
}
nav{
  background: black;
  height: 11vh;
}
<div>
  <nav>
  </nav>
</div>
like image 371
ivaylo Avatar asked Jun 18 '21 03:06

ivaylo


People also ask

What do called a space between the content and the border?

The Architecture: The content is surrounded by the border, the space between the content and the border is called the padding, while the space between the border and the other elements in the document is called the margin.

How do I get rid of h2 margin?

You can achieve this by removing the margin from the H2 element using css. If you only want to remove the space from the top or bottom of the <h2> element you can use the margin-top and margin-bottom CSS properties.

Why is there white space between my divs?

You get whitespace there because you have whitespace inbetween the divs. Whitespace between inline elements is interpreted as a space. However, this is a bad way to do what you want to do. You should float the elements if thats what you want to do.

How do I remove space between image and border in CSS?

Line Height Property: The CSS line-height-property can be used to set the height of the line, whose value is set to normal, by default. By setting the height of the container at 0%, the white space can be removed.


1 Answers

The problem is this:

border: 0.5vw solid red;

and that doesn't give you a whole number as such it anti-alias the border with the white DIV and what you are likely be seeing is more orange than white.

I've come up with a hack by having 2 separate divs one for the nav and that div background is black so your border is anti-alias to black rather than white.

Fiddle: http://jsfiddle.net/dg45wfc8/

*{
  padding: 0;
  margin: 0;
  font-size: 0;
  line-height: 0;
}
.content-div {
  min-height: calc(((100vh - 11vh) - 0.5vw));
  border: 0.5vw solid red;
  width: 100%;
  box-sizing: border-box;
  
  border-width: 0 0.5vw 0.5vw 0.5vw;
  border-style: solid;
  border-color: red;
}

nav{
  background: black;
  height: 11vh;
}

.nav-div {
 border-width: 0.5vw 0.5vw 0 0.5vw;
 border-style: solid;
 border-color: red;
 background: black;
}
<div class="nav-div">
  <nav>
  </nav>
</div>
<div class="content-div">>
</div>
like image 136
John Avatar answered Oct 17 '22 23:10

John