简体   繁体   English

我的元素之间奇怪的空白

[英]Odd White Space In Between my Elements

so for some reason there is some white space between my elements (using chrome browser).所以出于某种原因,我的元素之间有一些空白(使用 chrome 浏览器)。 I tried inspecting it and couldn't solve the issue.我尝试检查它,但无法解决问题。 Not sure what could be causing it at all.完全不知道是什么原因造成的。 I hosted a demo page here so you can see what I am talking about.在这里托管了一个演示页面所以你可以看到我在说什么。 在此处输入图片说明

So any idea what would be causing this?那么知道是什么导致了这种情况吗? I'll provide my CSS below for the elements in question.我将在下面为相关元素提供我的 CSS。 As you can see the blue element to the left does not have this same issue so I assume it has something to do with the gear elements.正如你所看到的,左边的蓝色元素没有同样的问题,所以我认为它与齿轮元素有关。

This is the only code I have on it right now:这是我现在唯一的代码:

.gear-item {
    position: relative;
    height: 320px;
    width: 320px;
    padding: 80px 25px 0px 55px;
    display: inline-block;
    clear: none;
}

.gear-item:nth-child(even) {
    background: #252627;
}

the whitespace you see is the actual whitespace in the html, inline elements will show whitespace between then, the easiest solution is to float the elements您看到的空白是 html 中的实际空白,内联元素将在两者之间显示空白,最简单的解决方案是浮动元素

.gear-item {
    position: relative;
    height: 320px;
    width: 320px;
    padding: 80px 25px 0px 55px;
    display: block;
    float:left;
    clear: none;
}

.gear-item:nth-child(even) {
    background: #252627;
}

Inline elements are sensitive to the white space in your code.内联元素对代码中的空白很敏感。 Remove the white space in your code between your divs and the space goes away.删除代码中 div 之间的空白区域,空间就会消失。

Its caused by using inline-block .它是由使用inline-block引起的。 Apparently the same problem described here: https://css-tricks.com/fighting-the-space-between-inline-block-elements/ .显然这里描述的问题相同: https : //css-tricks.com/fighting-the-space-between-inline-block-elements/ So it's actually the whitespace in your markup!所以它实际上是标记中的空白!

A quick fix would be using floats instead for gear-item :一个快速的解决方法是使用浮点数代替gear-item

display: block;
float: left;

(or some of the other solutions outlined in the link I mentioned) (或我提到的链接中概述的其他一些解决方案)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM