如何消除内联元素之间的空格的可见性?

发布于 2024-10-12 12:57:40 字数 679 浏览 7 评论 0原文

假设我有几个内联块 div 标签,就像此类

<div class="image">

</div>
<div class="image">

</div>

图像只是将其大小设置为 100x100 和灰色背景颜色。它们的边距和边框设置为 0,但两个矩形之间有间距。

但是,如果我编写这样的 HTML:

<div class="image">

</div><div class="image">

</div>

删除 div 之间的所有空白,间距就会消失。

因为我不想这样编写 HTML,所以我认为必须有一种方法可以使用 CSS 删除空格。我不在乎空白是否被删除、隐藏或缩小,只要它的可见性被删除即可。

感谢您的帮助


根据要求,JSFiddle: http://jsfiddle.net/6h3Jx/


已更新字间距: http://jsfiddle.net/6h3Jx/1/

Say I have several inline-block div tags, like this

<div class="image">

</div>
<div class="image">

</div>

class image just sets their size to 100x100 and a gray background color. Their margin and borders are set to 0, and yet there is spacing between the two rectangles.

If I write the HTML such as this, however:

<div class="image">

</div><div class="image">

</div>

Removing all whitespace between the divs, the spacing disappears.

Since I don't want to write my HTML like that, I'm thinking that there must be a way to remove whitespace using CSS. I don't care if the whitespace is removed, hidden or downsized as long as it's visibility is removed.

Thanks for any help


As requested, JSFiddle: http://jsfiddle.net/6h3Jx/


Updated with word-spacing: http://jsfiddle.net/6h3Jx/1/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

娇俏 2024-10-19 12:57:40

这是一种内联元素行为,因此请尝试向左浮动。 http://jsfiddle.net/aVrSx/

it is an inline element behaviour, so try floating left. http://jsfiddle.net/aVrSx/

埋葬我深情 2024-10-19 12:57:40

您可以设置“显示:flex;”属性到其父包装器:

.flexbox {
  display: -webkit-box;      /* OLD - iOS 6-, Safari 3.1-6 */
  display: -moz-box;         /* OLD - Firefox 19- (buggy but mostly works) */
  display: -ms-flexbox;      /* TWEENER - IE 10 */
  display: -webkit-flex;     /* NEW - Chrome */
  display: flex;             /* NEW, Spec - Opera 12.1, Firefox 20+ */
}

you can set "display: flex;" attribute to their parent wrapper:

.flexbox {
  display: -webkit-box;      /* OLD - iOS 6-, Safari 3.1-6 */
  display: -moz-box;         /* OLD - Firefox 19- (buggy but mostly works) */
  display: -ms-flexbox;      /* TWEENER - IE 10 */
  display: -webkit-flex;     /* NEW - Chrome */
  display: flex;             /* NEW, Spec - Opera 12.1, Firefox 20+ */
}
浅笑依然 2024-10-19 12:57:40

将以下内容放在父元素上:

word-spacing:-4px;

或者尝试:

font-size:0px;

它可能会工作得更好,因为它不会受到文本大小调整的影响。

put the following on a parent element:

word-spacing:-4px;

Or try:

font-size:0px;

It might work even better as it will not be affected by text resizing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文