css - 尝试将 div 放置在按钮下方,但无法将其与按钮右侧对齐

标签 css flexbox

我正在使用 React,我有一排按钮,其中一个按钮应该打开一个包含一些点击信息的 div。

不过,我在使用 CSS 时遇到了一些问题。这是一个示例 fiddle :https://jsfiddle.net/4ovxw4eg/1/

和片段:

.container {
  display: flex;
  flex-direction: row;
}

.openItem {
  height: 200px;
  width: 200px;
  border: 1px solid black;
  position: absolute;
  right: 0;
}

.test {
  position: relative;
}
<div class="container">
  <button>
    some button
  </button>
  <button>
    some button
  </button>
  <button>
    some button
  </button>
  <button>
    some button
  </button>
  <button class="test">
    The Button
  </button>
</div>

<div class="openItem">
  This should be below and to the right edge of The Button
</div>

我应该如何处理这个问题?我正在为按钮行使用 flexbox 。

我的 React 代码会检查 someProp 是否为 true,然后显示此框。 IE。 showPopup && renderPopup

最佳答案

将 div 移到按钮的容器 div 内,并使用 inline-flex 和相对位置。

.container {
  display: inline-flex;
  flex-direction: row;
  position: relative;
}

.openItem {
  height: 200px;
  width: 200px;
  border: 1px solid black;
  position: absolute;
  right: 0;
  top: 40px;
}

.test {
  position: relative;
}
<div class="container">
  <button>
    some button
  </button>
  <button>
    some button
  </button>
  <button>
    some button
  </button>
  <button>
    some button
  </button>
  <button class="test">
    The Button
  </button>
  <div class="openItem">
    This should be below and to the right edge of The Button
  </div>
</div>

关于css - 尝试将 div 放置在按钮下方,但无法将其与按钮右侧对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47663164/

相关文章:

css - 使用 CSS3 的六边形

html - Cordova 上的谷歌字体的多名称图标呈现两个不同的图标

html - 文字在图像下方流动

javascript - 为按钮组 react native 按钮映射

css - 在带换行的列 flex 方向上,垂直滚动优先于水平滚动

html - &lt;!DOCTYPE html> 打破 flexbox flex

html - css继承类不起作用

html - flex 和溢出 : weird behaviour

html - Safari 6 (iOS 6) flex 布局不换行元素

HTML CSS flexbox 图像和文本