html - 对齐同一行不同高度的元素

标签 html css flexbox

我试图在同一水平轴上显示多个圆圈,但宽度和高度不同。问题是圆圈缩小了。

body,
html {
  height: 100%;
  margin: 0;
  padding: 0;
}

.circles-container {
  display: table;
  border-spacing: 40px;
}

.row {
  display: table-row;
}

.circle {
  width: 100px;
  height: 100px;
  border: 1px solid #000;
  border-radius: 50%;
  text-align: center;
  vertical-align: middle;
  display: table-cell;
}

.cell {
  display: table-cell;
}

.big-circle {
  width: 300px;
  height: 300px;
}
<div class="circles-container">
  <div class="row">
    <div class="cell">
      <div class="circle">
        <span>TEXT</span>
      </div>
    </div>
    <div class="cell">
      <div class="circle">
        <span>TEXT</span>
      </div>
    </div>
    <div class="cell">
      <div class="big-circle circle">
        <span>TEXT</span>
      </div>
    </div>
    <div class="cell">
      <div class="circle">
        <span>TEXT</span>
      </div>
    </div>
    <div class="cell">
      <div class="big-circle circle">
        <span>TEXT</span>
      </div>
    </div>
  </div>
</div>

JSFIDDLE:https://jsfiddle.net/cxuxgy0u/

最佳答案

您不应该为此使用表格布局。您的 HTML 在语义上不表示表格,因此 table 元素不适合使用。

你想做的事情都可以用 Flexbox 来实现。

article {
  display: flex;
  align-items: center;
}

article > div + div {
  margin-left: 1rem;
}

article > div {
  flex-shrink: 0;
  height: 4rem;
  width: 4rem;
  border-radius: 50%;
  border: solid 1px black;
  display: flex;
  justify-content: center;
  align-items: center;
}

article > div:nth-child(2) {
  height: 6rem;
  width: 6rem;
}
<article>
  <div><span>TEXT</span></div>
  <div><span>TEXT</span></div>
  <div><span>TEXT</span></div>
  <div><span>TEXT</span></div>
  <div><span>TEXT</span></div>
  <div><span>TEXT</span></div>
  <div><span>TEXT</span></div>
  <div><span>TEXT</span></div>
  <div><span>TEXT</span></div>
</article>

您可能想要 read more about Flexbox on MDN .

关于html - 对齐同一行不同高度的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45679634/

相关文章:

php - 如何创建下载链接来下载文件而不是重定向到浏览器?

html - 子元素悬停,影响父元素

javascript - CSS 中的最小/最大绝对位置

html - 带有 Flex Box 的响应式 CSS

html - 为什么我的 svg 没有在 div 容器中居中?

javascript - 在输入时触发焦点事件时使 HTML5 数据列表可见

javascript - 连接两个页面内的数据

html - 如何将 CSS 样式添加到 HTML 中的聚焦 anchor

jquery - 容器不随(kwicks 插件)内容增长

html - Internet Explorer 忽略 flexbox 容器的宽度