简体   繁体   English

Tailwind CSS 中的不同对齐方式

[英]Different Alignments in Tailwind CSS

I have three divs: a nav bar, a webgl player, and a panel.我有三个 div:一个导航栏、一个 webgl 播放器和一个面板。 I want the navbar at the top, and beneath it the panel aligned to the right hand side of the screen, and the webgl player to be centered vertically and horizontally in the remaining space.我希望导航栏位于顶部,其下方的面板与屏幕右侧对齐,并且 webgl 播放器在剩余空间中垂直和水平居中。

items-center sucessefully centers things vertically. items-center成功地将事物垂直居中。

For the correct horizonal positioning, so far I have tried justify-between which successfully places the panel against the right edge, but also places the webgl player against the left edge of the screen, which is undesirable.对于正确的水平定位,到目前为止,我已经尝试过justify-between ,它成功地将面板放在右边缘,但也将 webgl 播放器放在屏幕的左边缘,这是不可取的。

justify-center places them both in the middle, wherein I expected place-self-end on the right-hand element to correctly place it, but it didn't move at all. justify-center将它们都放在中间,我希望place-self-end它们放在右侧元素上以正确放置它,但它根本没有移动。

Minimal Code example:最小代码示例:

<div class="flex flex-col">
  <div class="bg-green-500 py-12 flex flex-col justify-center"></div>
  <div class="flex flex-row justify-center items-center">
    <div class="bg-blue-500 w-80 h-60 center"></div>
    <div class="bg-red-500 w-80 h-screen "></div>
  </div>
</div>

Can also be found here: https://play.tailwindcss.com/y3uXkVYcWs也可以在这里找到: https://play.tailwindcss.com/y3uXkVYcWs

Desired Result:期望的结果: 所需布局 Where Green is Navbar, Blue is first div, Red is second div.其中绿色是导航栏,蓝色是第一个 div,红色是第二个 div。

After writing all of this, I finally found this answer: In CSS Flexbox, why are there no "justify-items" and "justify-self" properties?写完这一切,我终于找到了这个答案: 在CSS Flexbox中,为什么没有“justify-items”和“justify-self”属性?

This says to drop any justify and items-center and instead use margin: auto on the blue element这表示要删除任何justifyitems-center而是在蓝色元素上使用margin: auto

HTML HTML

<div class="flex flex-col">
  <div class="bg-green-500 py-12 flex flex-col"></div>
  <div class="flex flex-row justify-center">
    <div class="bg-blue-500 w-80 h-60 center" id="webglPlayer"></div>
    <div class="bg-red-500 w-80 h-screen" ></div>
  </div>
</div>

CSS CSS

@tailwind base;
@tailwind components;
@tailwind utilities;

#webglPlayer {
    margin: auto;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM