Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove space between div content and border?

I have div inside another div. If I have a border in the outer div I got a space in Microsoft Edge browser in some scales (100% or 125%). I think it's a rounding bug, but I don't know how to get rid of it.

html:

<div class="outer">
    <div class="inner"></div>
</div>

css:

.outer {
    background-color: black;
    float: left;
    border: 1px solid white;
}

.inner {
    width: 300px;
    height: 300px;
    background-color: yellow;
}

jsfiddle: https://jsfiddle.net/EvgeniiMalikov/4bbx9p5w/

As you can see there is black background visible between outer and inner div. If you don't see it try to change scale.

UPDATE: the gap really appears not between div elements, it's inside inner div close to its border. Discovered it by adding outline to inner div.

example screenshot

example screenshot

example screenshot with border and outline (gap between border and outline) example with outline

box-sizing: border-box;
border: 1px solid lime;
outline: 1px solid lime;
like image 298
Evgenii Malikov Avatar asked Nov 23 '15 11:11

Evgenii Malikov


People also ask

How do I reduce the space between text and borders?

You can use line-height for decrease distance. Drawback of this method -- because we use block display it works only for single line of the text. Show activity on this post. You can use background with linear-gradient to produce a border, and with it you can position it anywhere.

How can I remove space between div elements?

There are two methods for removal of space between two divs or two elements. First one is, assign the font size of the parent of the inline block element to 0px and then assign the proper font-size to the inline block element. and Second is, Make the display of the parent element to flex.

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 a gap between my divs?

The gap is the result of the margin of the paragraph escaping from its container. Give me a minute to look at the page and I'll offer more info. EDIT: @RyanReese nailed it. It's just a margin collapse issue.


1 Answers

the border 1px is adding to the width 300px. you need to remove 1px from the width

.outer{background-color: black; float: left; border: 1px solid white}
.inner{width: 299px; height: 300px; background-color: yellow}

Here is the screenshot from Microsoft Edge enter image description here

like image 167
Rami Sarieddine Avatar answered Oct 13 '22 17:10

Rami Sarieddine