可以在Tailwind CSS 3.0中使用”top”和”calc”吗?

huangapple go评论73阅读模式
英文:

can I use top and calc within Tailwind CSS 3.0

问题

以下是您提供的内容的翻译:

所以我正在尝试在Tailwind中使用calc和top。我知道这个可以正常工作

<div className="w-60 h-[calc(100vh-5rem)]">侧边栏</div>

然而,我似乎无法使绝对定位的元素像这样一起下降

<div className="w-60 absolute top-[calc(100%-5rem)]">侧边栏</div>

除了尝试之外,我似乎找不到任何证据表明它是否有效。除了基本的类之外,是否还需要包含其他Tailwind类吗?

由我编辑,东部时间晚上8:32
此处的top-calc不适用于data-shop-area

<!DOCTYPE html>
<html lang="en" class="scroll-smooth">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="./css/site.css" />
    <link rel="stylesheet" href="./css/notailwind.css" />
    <link
      rel="stylesheet"
      href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"
      integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw=="
      crossorigin="anonymous"
      referrerpolicy="no-referrer"
    />
    <script src="./js/site.js" defer></script>

    <title>Al's Tailwind Css Boiler Plate</title>
  </head>

  <body class="m-0">
    <header id="top" class="mt-0">
      <section
        class="fixed top-0 flex w-full items-center justify-between gap-2 bg-black px-5 py-2 duration-700"
        data-main
        id="main-nav"
      >
        <div id="brand-logo">
          <a href="#top"> <img class="w-28 rounded-full" src="https://assets.bigcartel.com/theme_images/95510953/3332963E-85A8-4A3F-9A8A-7EAD04CA73C5.jpeg" alt="Wolf Logo" /></a>
        </div>

        <div class="mr-4 flex items-center gap-2">
          <div class="md:block" id="cart-div">
            <div class="relative hidden md:block">
              <a data-shop-btn class="block" id="sc" href="#">
                <i class="fa-solid fa-shopping-cart px-6"></i>
              </a>
              <div data-shop-tri class="absolute top-full" id="triangle"></div>
              <div data-shop-area class="top-[calc(100% - 20px)] absolute right-3 w-96 rounded-sm bg-white py-4 text-center text-black shadow-md">
                <div class="my-6 text-xl">您的购物袋是空的</div>
                <a class="my-6 rounded-md bg-black p-2 text-white" href="#">开始购物</a>
              </div>
            </div>
          </div>

          <div class="block pr-3 text-5xl text-white md:hidden" data-ham-btn id="ham-btn">
            <i data-i class="fa-solid fa-bars"></i>
          </div>
          <nav data-main-nav class="hidden gap-3 md:flex">
            <a href="./index.html#eat">吃那些</a>
            <a href="./index.html#products">产品</a>
            <a href="./index.html#contact">联系</a>
          </nav>
        </div>
      </section>

      <section class="fixed top-32 hidden h-full w-full bg-black pt-10 md:hidden" data-mobile-nav id="mobile-nav">
        <nav class="mx-auto flex w-2/3 flex-col gap-2 px-3 text-center md:hidden">
          <a href="./index.html#eat">吃那些</a>
          <a href="./index.html#products">产品</a>
          <a href="./index.html#contact">联系</a>
        </nav>
      </section>
    </header>

    <main>
      <section data-item-num>
        <div class="mx-auto grid h-screen w-10/12 items-center justify-items-center gap-0 md:grid-cols-2" id="card">
          <div id="card-image">
            <img class="w-full overflow-hidden object-contain" src="./images/blacktbiglogo.png" alt="Black T-shirt Big Logo" />
          </div>
          <div class="grid gap-5 text-center" id="card-info">
            <a href="#">
              <p class="text-base md:text-3xl">黑色狼标大号T恤</p>
            </a>
            <p class="text-base text-red-600">$25.00 - $30.00</p>
            <form class="grid justify-items-center gap-1" action="post">
              <select class="w-1/2 rounded-sm border border-black p-3 text-center" name="size" id="size">
                <option value="" selected disabled>选择尺寸</option>
                <option value="small">小号</option>
                <option value="medium">中号</option>
                <option value="large">大号</option>
                <option value="x-large">特大号</option>
                <option value="xx-large">特特大号</option></select
              ><br />
              <button class="w-1/2 rounded-sm bg-black p-3 text-center text-base text-white duration-500 hover:bg-slate-700 md:text-lg" type="submit">添加到购物袋 - $30.00</button>
            </form>

            <p>黑色T恤,100%棉,前中央有大号白色狼标志。</p>
          </div>
        </div>
      </section>
    </main>
    <div id="mobile-shopping-cart" class="shoppin-cart md:hidden">
      <a href="#shopping">
        <i class="fa-solid fa-shopping-cart fixed bottom-0 w-full bg-slate-800 p-2 text-center text-white hover-bg-slate-600"></i>
      </a>
    </div>
    <footer class="z-50 mx-0 flex min-h-full min-w-full flex-col justify-center bg-black p-4 text-center text-white md

<details>
<summary>英文:</summary>

So I am trying to use calc wit the top in tailwind. I know this works fine 
```html
&lt;div className=&quot;w-60 h-[calc(100vh-5rem)]&quot;&gt;Sidebar&lt;/div&gt;

however I can't seem to get something that is absoluet to drop with it like such

&lt;div className=&quot;w-60 absolute top-[calc(100%-5rem)]&quot;&gt;Sidebar&lt;/div&gt;

I can't seem to find any evidence whether or not it works or does not work besides trying it. Is there another tailwind class I need to include besides the basic ones??

Edited by me 8:32pm Eastern time
this top-calc not working on data-shop-area

&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot; class=&quot;scroll-smooth&quot;&gt;
  &lt;head&gt;
    &lt;meta charset=&quot;UTF-8&quot; /&gt;
    &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot; /&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot; /&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;./css/site.css&quot; /&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;./css/notailwind.css&quot; /&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css&quot; integrity=&quot;sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw==&quot; crossorigin=&quot;anonymous&quot; referrerpolicy=&quot;no-referrer&quot; /&gt;
    &lt;script src=&quot;./js/site.js&quot; defer&gt;&lt;/script&gt;

    &lt;title&gt;Al&#39;s Tailwind Css Boiler Plate&lt;/title&gt;
  &lt;/head&gt;

  &lt;body class=&quot;m-0&quot;&gt;
    &lt;header id=&quot;top&quot; class=&quot;mt-0&quot;&gt;
      &lt;section class=&quot;fixed top-0 flex w-full items-center justify-between gap-2 bg-black px-5 py-2 duration-700&quot; data-main id=&quot;main-nav&quot;&gt;
        &lt;div id=&quot;brand-logo&quot;&gt;
          &lt;a href=&quot;#top&quot;&gt; &lt;img class=&quot;w-28 rounded-full&quot; src=&quot;https://assets.bigcartel.com/theme_images/95510953/3332963E-85A8-4A3F-9A8A-7EAD04CA73C5.jpeg&quot; alt=&quot;Wolf Logo&quot; /&gt;&lt;/a&gt;
        &lt;/div&gt;

        &lt;div class=&quot;mr-4 flex items-center gap-2&quot;&gt;
          &lt;div class=&quot;md:block&quot; id=&quot;cart-div&quot;&gt;
            &lt;div class=&quot;relative hidden md:block&quot;&gt;
              &lt;a data-shop-btn class=&quot;block&quot; id=&quot;sc&quot; href=&quot;#&quot;&gt;
                &lt;i class=&quot;fa-solid fa-shopping-cart px-6&quot;&gt;&lt;/i&gt;
              &lt;/a&gt;
              &lt;div data-shop-tri class=&quot;absolute top-full&quot; id=&quot;triangle&quot;&gt;&lt;/div&gt;
              &lt;div data-shop-area class=&quot;top-[calc(100% - 20px)] absolute right-3 w-96 rounded-sm bg-white py-4 text-center text-black shadow-md&quot;&gt;
                &lt;div class=&quot;my-6 text-xl&quot;&gt;Your bag is empty&lt;/div&gt;
                &lt;a class=&quot;my-6 rounded-md bg-black p-2 text-white&quot; href=&quot;#&quot;&gt;Start shopping&lt;/a&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;

          &lt;div class=&quot;block pr-3 text-5xl text-white md:hidden&quot; data-ham-btn id=&quot;ham-btn&quot;&gt;
            &lt;i data-i class=&quot;fa-solid fa-bars&quot;&gt;&lt;/i&gt;
          &lt;/div&gt;
          &lt;nav data-main-nav class=&quot;hidden gap-3 md:flex&quot;&gt;
            &lt;a href=&quot;./index.html#eat&quot;&gt;Eat Those &lt;/a&gt;
            &lt;a href=&quot;./index.html#products&quot;&gt;Products&lt;/a&gt;
            &lt;a href=&quot;./index.html#contact&quot;&gt;Contact&lt;/a&gt;
          &lt;/nav&gt;
        &lt;/div&gt;
      &lt;/section&gt;

      &lt;section class=&quot;fixed top-32 hidden h-full w-full bg-black pt-10 md:hidden&quot; data-mobile-nav id=&quot;mobile-nav&quot;&gt;
        &lt;nav class=&quot;mx-auto flex w-2/3 flex-col gap-2 px-3 text-center md:hidden&quot;&gt;
          &lt;a href=&quot;./index.html#eat&quot;&gt;Eat Those &lt;/a&gt;
          &lt;a href=&quot;./index.html#products&quot;&gt;Products&lt;/a&gt;
          &lt;a href=&quot;./index.html#contact&quot;&gt;Contact&lt;/a&gt;
        &lt;/nav&gt;
      &lt;/section&gt;
    &lt;/header&gt;

    &lt;main&gt;
      &lt;section data-item-num&gt;
        &lt;div class=&quot;mx-auto grid h-screen w-10/12 items-center justify-items-center gap-0 md:grid-cols-2&quot; id=&quot;card&quot;&gt;
          &lt;div id=&quot;card-image&quot;&gt;
            &lt;img class=&quot;w-full overflow-hidden object-contain&quot; src=&quot;./images/blacktbiglogo.png&quot; alt=&quot;Black T-shirt Big Logo&quot; /&gt;
          &lt;/div&gt;
          &lt;div class=&quot;grid gap-5 text-center&quot; id=&quot;card-info&quot;&gt;
            &lt;a href=&quot;#&quot;&gt;
              &lt;p class=&quot;text-base md:text-3xl&quot;&gt;Black Wolf T-Shirt Big Logo&lt;/p&gt;
            &lt;/a&gt;
            &lt;p class=&quot;text-base text-red-600&quot;&gt;$25.00 - $30.00&lt;/p&gt;
            &lt;form class=&quot;grid justify-items-center gap-1&quot; action=&quot;post&quot;&gt;
              &lt;select class=&quot;w-1/2 rounded-sm border border-black p-3 text-center&quot; name=&quot;size&quot; id=&quot;size&quot;&gt;
                &lt;option value=&quot;&quot; selected disabled&gt;Choose Size&lt;/option&gt;
                &lt;option value=&quot;small&quot;&gt;Small&lt;/option&gt;
                &lt;option value=&quot;medium&quot;&gt;Medium&lt;/option&gt;
                &lt;option value=&quot;large&quot;&gt;Large&lt;/option&gt;
                &lt;option value=&quot;x-large&quot;&gt;X-Large&lt;/option&gt;
                &lt;option value=&quot;xx-large&quot;&gt;XX-Large&lt;/option&gt;&lt;/select
              &gt;&lt;br /&gt;
              &lt;button class=&quot;w-1/2 rounded-sm bg-black p-3 text-center text-base text-white duration-500 hover:bg-slate-700 md:text-lg&quot; type=&quot;submit&quot;&gt;Add To Bag - $30.00&lt;/button&gt;
            &lt;/form&gt;

            &lt;p&gt;Unisex Black T-shirt, 100% Cotton, with the big white wolf logo on the front center.&lt;/p&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/section&gt;
    &lt;/main&gt;
    &lt;div id=&quot;mobile-shopping-cart&quot; class=&quot;shoppin-cart md:hidden&quot;&gt;
      &lt;a href=&quot;#shopping&quot;&gt;
        &lt;i class=&quot;fa-solid fa-shopping-cart fixed bottom-0 w-full bg-slate-800 p-2 text-center text-white hover:bg-slate-600&quot;&gt;&lt;/i&gt;
      &lt;/a&gt;
    &lt;/div&gt;
    &lt;footer class=&quot;z-50 mx-0 flex min-h-full min-w-full flex-col justify-center bg-black p-4 text-center text-white md:mt-4 md:bg-gray-300 md:text-black&quot;&gt;
      &lt;p class=&quot;p-3 text-xl&quot;&gt;
        Reach out on these platforms as well:

        &lt;a href=&quot;#&quot;&gt;&lt;i class=&quot;fa-brands fa-facebook&quot;&gt;&lt;/i&gt;&lt;/a&gt;
        &lt;a href=&quot;#&quot;&gt;&lt;i class=&quot;fa-brands fa-twitter&quot;&gt;&lt;/i&gt;&lt;/a&gt;
        &lt;a href=&quot;#&quot;&gt;&lt;i class=&quot;fa-brands fa-instagram&quot;&gt;&lt;/i&gt;&lt;/a&gt;
        &lt;a href=&quot;#&quot;&gt;&lt;i class=&quot;fa-brands fa-tiktok&quot;&gt;&lt;/i&gt;&lt;/a&gt;
      &lt;/p&gt;
      &lt;br /&gt;
      &lt;p&gt;Powered by Big Cartel&lt;/p&gt;
    &lt;/footer&gt;
  &lt;/body&gt;
&lt;/html&gt;

you can see th link here tailwind play

答案1

得分: 0

以下是您要翻译的部分:

"You should attach a larger part of the code, this will make the answer easier
Until then...

You must ensure that you are using the correct version of Tailwind
And make sure that the parent of the element using Position Absolute has a specified length

Here is the code that does what you want and attached a picture of the results ..

Sidebar

"

请注意,其中的代码和英文文本是原样保留的。

英文:

You should attach a larger part of the code, this will make the answer easier
Until then...

You must ensure that you are using the correct version of Tailwind
And make sure that the parent of the element using Position Absolute has a specified length

Here is the code that does what you want and attached a picture of the results ..

&lt;div class=&quot;relative h-80 overflow-hidden bg-red-500&quot;&gt;
&lt;div class=&quot;w-80 bg-blue-400 absolute top-[calc(100%-50px)]&quot;&gt;Sidebar&lt;/div&gt;
&lt;/div&gt;

可以在Tailwind CSS 3.0中使用”top”和”calc”吗?

huangapple
  • 本文由 发表于 2023年6月12日 03:22:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76452176.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定