【问题标题】:Keeping a div at the bottom of it's parent always始终将 div 放在其父级的底部
【发布时间】:2022-01-22 02:26:56
【问题描述】:

我的组件

return (
    <div>
      <section>
        <div class="md:grid md:grid-cols-2 gap-4">
          {pinnedRepos.map((r) => {
            const bgColor = {
              backgroundColor: r.node.primaryLanguage.color,
            };

            return (
              <div
                id="project-outer-container"
                class="text-sm border-solid border border-gray-300 rounded shadow mb-4 md:mb-0 pb-4">
                <div id="project-inner-container" class="p-4 relative">
                  <div id="project-title" class="flex items-center">
                    <span class="mr-3 text-xl">
                      <GoRepo />
                    </span>
                    <a href={r.node.url}>{r.node.name}</a>
                  </div>
                  <div class="flex flex-col justify-between">
                    <div id="project-about" class="">
                      <p class="">{r.node.description}</p>
                    </div>
                    <div id="project-lang" class="flex items-center content-end">
                      <div style={bgColor} class="rounded-full h-3 w-3"></div>
                      <span class="ml-3">{r.node.primaryLanguage.name}</span>
                    </div>
                  </div>
                </div>
              </div>
            );
          })}
        </div>
      </section>
    </div>
  );

我想保留这个部分...

<div id="project-lang" class="flex items-center content-end">
                      <div style={bgColor} class="rounded-full h-3 w-3"></div>
                      <span class="ml-3">{r.node.primaryLanguage.name}</span>
                    </div>

始终位于其父级的底部。否则我最终会得到这样的东西:

看起来很乱。我已经尝试了多个 flexbox 对齐和合理的裁决。我已将父元素设置为绝对元素,将子元素设置为相对元素。

我什至尝试过使用粘性页脚的方式,但没有。

任何能让我朝着正确方向前进的 CSS 向导都会很棒

【问题讨论】:

  • 将 h-100 或 height:100vh 添加到父级,然后您将获得所需的输出
  • 感谢 Tailwind v3 现在 h-full

标签: javascript html css tailwind-css


【解决方案1】:

有了上面的提示,我就是这样做的

<div
                id="project-outer-container"
                class="text-sm border-solid border border-slate-300 dark:border-slate-700 rounded shadow mb-4 md:mb-0 pb-4">
                <div id="project-inner-container" class="p-4 h-full relative">
                  <div id="project-title" class="flex items-center">
                    <span class="mr-3 text-xl">
                      <GoRepo />
                    </span>
                    <a href={r.node.url}>{r.node.name}</a>
                  </div>
                  <div id="project-about" class="">
                    <p class="">{r.node.description}</p>
                  </div>
//----------------- this is what I wanted to be placed at the bottom
                  <div id="project-lang" class="flex items-center absolute bottom-0">
                    <div style={bgColor} class="rounded-full h-3 w-3"></div>
                    <span class="ml-3">{r.node.primaryLanguage.name}</span>
                  </div>
                </div>
              </div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-09
    • 2014-09-13
    • 1970-01-01
    • 2011-04-27
    • 2011-01-09
    • 2022-01-25
    相关资源
    最近更新 更多