以下是我的代码:

.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.button {
  padding: 5px;
  background-color: rgb(200, 200, 200);
}
<div class="buttons">

  <div class="button">
    One
  </div>

  <div class="button">
    Two
  </div>

  <div class="button" tabindex="0" contenteditable="true" spellcheck="false">
    Three
  </div>

</div>

现在,如果我点击第三个按钮的右边,不再点击按钮,只是在右边的某个地方,那么第三个按钮仍然被激活.为什么?这太奇怪了!

enter image description here

这只会发生一次!

inline-flex代替会有帮助,但我需要flex,如果我在按钮左侧的小空白处点击下一个按钮,它仍然会发生.

推荐答案

Very Simple Workaround

正如@RokoC.Buljan在一条 comments 中指出的那样,这个问题似乎是Chromium漏洞.

简单的解决方法是在最后一个按钮后添加<wpr>标签.这Line Break Opportunity基本上是一个空元素.然而,您也可以使用&nbsp;不间断空间实体,它同样有效.

Test Snippet

.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.button {
  padding: 5px;
  background-color: rgb(200, 200, 200);
}
<h4>1. Original without workaround</h4>
<div class="buttons">
  <div class="button">
    One
  </div>
  <div class="button">
    Two
  </div>
  <div class="button" tabindex="0" contenteditable="true" spellcheck="false">
    Three
  </div>
</div>

<h4>2. Using a word-break opportunity tag</h4>
<div class="buttons">
  <div class="button">
    One
  </div>
  <div class="button">
    Two
  </div>
  <div class="button" tabindex="0" contenteditable="true" spellcheck="false">
    Three
  </div>
  <wbr>
</div>

<h4>3. Using a non-breaking space entity</h4>
<div class="buttons">
  <div class="button">
    One
  </div>
  <div class="button">
    Two
  </div>
  <div class="button" tabindex="0" contenteditable="true" spellcheck="false">
    Three
  </div>
  &nbsp;
</div>

Html相关问答推荐

如何删除html原生对话框的宽度

使用固定的HTML代码创建两个可向右滚动的行

CSS动画积分计数器

有没有可能设置div的边框宽度相对于其父宽度和高度?'

如何通过扭曲元素来倾斜元素?

使用css第n个子元素,如何迭代Y组中的X个元素?

为什么我的搜索栏会出现在WONG位置?

如何翻转卡片图像的背面

风格规则应该适用于响应图像的哪些方面?哪种规则适用于<;图片和gt;,哪种规则适用于<;img>;?

Html视频标签:圆角像素化

如何将文本环绕心形(而不仅仅是圆形)?

文本css后面未显示背景 colored颜色

为什么要添加换行符(至少在 Google Chrome 中)

为什么当我按第三个按钮时,前两个按钮会跳动?

如何使粘性导航栏能够跨其他组件工作?

我如何设置括号的样式,使它们不会挂在旁边的其他字符下面

在 html 邮箱的左侧和右侧制作多个元素很热门吗?

右对齐 bootstrap 导航项而不是下拉菜单

使用 Selenium for Python 在网站上查找类名称中包含换行符的元素

无法使用 HTML 中的 Bootstrap 自上而下居中