如何使两个边框重叠?

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

How to make 2 borders overlap?

问题

我使用Tailwind,需要实现以下效果:

如何使两个边框重叠?

所以我在父元素和两个按钮(增加和减少)上加了边框。

问题:当有两个边框时,我们可以看到它。而且渲染结果不符合我的模板:

如何使两个边框重叠?

我添加了类-m-px,但不够。

这是playground

这是代码:

<div class="flex flex-col gap-2 p-8">
  <div class="flex w-fit items-center rounded border border-solid border-neutral-300">
    <button type="button" class="-m-px mr-0 h-10 w-10 rounded border border-solid border-neutral-300 bg-transparent hover:cursor-pointer focus:outline-none">
      -
    </button>

    <input id="{id}" type="number" value="0" class="h-10 w-16 rounded border-none text-center text-base font-semibold focus:outline-none" />

    <button type="button" class="-m-px ml-0 h-10 w-10 rounded border border-solid border-neutral-300 bg-transparent hover:cursor-pointer focus:outline-none">
      +
    </button>
  </div>
</div>

谢谢你的帮助!

英文:

I use tailwind and i need to achieve this :
如何使两个边框重叠?

So I made a border on the parent element and on both buttons (increment and decrement).

Problem : when there are 2 borders, we can see it. And the render is not like my template :
如何使两个边框重叠?

I added class -m-px but not sufficient.

Here is the playground

Here is the code :

&lt;div class=&quot;flex flex-col gap-2 p-8&quot;&gt;
  &lt;div class=&quot;flex w-fit items-center rounded border border-solid border-neutral-300&quot;&gt;
    &lt;button type=&quot;button&quot; class=&quot;-m-px mr-0 h-10 w-10 rounded border border-solid border-neutral-300 bg-transparent hover:cursor-pointer focus:outline-none&quot;&gt;
      -
    &lt;/button&gt;

    &lt;input id=&quot;{id}&quot; type=&quot;number&quot; value=&quot;0&quot; class=&quot;h-10 w-16 rounded border-none text-center text-base font-semibold focus:outline-none&quot; /&gt;

    &lt;button type=&quot;button&quot; class=&quot;-m-px ml-0 h-10 w-10 rounded border border-solid border-neutral-300 bg-transparent hover:cursor-pointer focus:outline-none&quot;&gt;
      +
    &lt;/button&gt;
  &lt;/div&gt;
&lt;/div&gt;

Thank you for your help !

答案1

得分: 1

你可以考虑在div的其中一边使用任意值,如果你只想在div的一边有1像素。

<div class="flex flex-col gap-2 p-8">
  <div class="flex w-fit items-center rounded border border-solid border-neutral-300">
    <button type="button" class="mr-0 h-10 w-10 rounded border-r-[1px] border-solid border-neutral-300 bg-transparent hover:cursor-pointer focus:outline-none">-</button>

    <input id="{id}" type="number" value="0" class="h-10 w-16 rounded border-none text-center text-base font-semibold focus:outline-none" />

    <button type="button" class="h-10 w-10 rounded border-l-[1px] border-solid border-neutral-300 bg-transparent hover:cursor-pointer focus:outline-none">+</button>
  </div>
</div>

编辑:

0被稍微向左放置,因为上下箭头允许用户增加/减少值。

要移除这个,你需要在css文件中添加以下代码:

@layer components {
  input[type="number"]::-webkit-inner-spin-button,
  input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }
}

最终输出:

如何使两个边框重叠?

Tailwind-css

英文:

You can consider using arbitary value if you want to have 1px in only one side of the div

如何使两个边框重叠?

&lt;div class=&quot;flex flex-col gap-2 p-8&quot;&gt;
  &lt;div class=&quot;flex w-fit items-center rounded border border-solid border-neutral-300&quot;&gt;
    &lt;button type=&quot;button&quot; class=&quot;mr-0 h-10 w-10 rounded border-r-[1px] border-solid border-neutral-300 bg-transparent hover:cursor-pointer focus:outline-none&quot;&gt;-&lt;/button&gt;

    &lt;input id=&quot;{id}&quot; type=&quot;number&quot; value=&quot;0&quot; class=&quot;h-10 w-16 rounded border-none text-center text-base font-semibold focus:outline-none&quot; /&gt;

    &lt;button type=&quot;button&quot; class=&quot;h-10 w-10 rounded border-l-[1px] border-solid border-neutral-300 bg-transparent hover:cursor-pointer focus:outline-none&quot;&gt;+&lt;/button&gt;
  &lt;/div&gt;
&lt;/div&gt;


Edit:

Zero is placed slightly left because of the up and down arrows which will let the user to increment/decrement the value.

如何使两个边框重叠?

To remove this you need to add following code in the css file

@layer components {
  input[type=&quot;number&quot;]::-webkit-inner-spin-button,
  input[type=&quot;number&quot;]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }
}

Final Output:

如何使两个边框重叠?

Tailwind-css

答案2

得分: 0

你可以在按钮样式中添加 style=border-(left/right): 1px solid #ccc;

样式为 border-right: 1px solid #ccc;

<div class="flex flex-col gap-2 p-8">
  <div class="flex w-fit items-center rounded border border-solid border-neutral-300">
    <button type="button" class="-m-px mr-0 h-10 w-10 rounded border border-solid border-neutral-300 bg-transparent hover:cursor-pointer focus:outline-none style="border-right: 1px solid #ccc;">
      -
    </button>
    <input id="{id}" type="number" value="0" class="h-10 w-16 rounded border-none text-center text-base font-semibold focus:outline-none" />
    <button type="button" class="-m-px ml-0 h-10 w-10 rounded border border-solid border-neutral-300 bg-transparent hover:cursor-pointer focus:outline-none style="border-left: 1px solid #ccc;">
      +
    </button>
  </div>
</div>
英文:

You can add style=border-(left/right): 1px solid #ccc; to the button style.

style="border-right: 1px solid #ccc;

&lt;div class=&quot;flex flex-col gap-2 p-8&quot;&gt;
  &lt;div class=&quot;flex w-fit items-center rounded border border-solid border-neutral-300&quot;&gt;
    &lt;button type=&quot;button&quot; class=&quot;-m-px mr-0 h-10 w-10 rounded border border-solid border-neutral-300 bg-transparent hover:cursor-pointer focus:outline-none style=&quot;border-right: 1px solid #ccc;&quot;&gt;
      -
    &lt;/button&gt;
    &lt;input id=&quot;{id}&quot; type=&quot;number&quot; value=&quot;0&quot; class=&quot;h-10 w-16 rounded border-none text-center text-base font-semibold focus:outline-none&quot; /&gt;

    &lt;button type=&quot;button&quot; class=&quot;-m-px ml-0 h-10 w-10 rounded border border-solid border-neutral-300 bg-transparent hover:cursor-pointer focus:outline-none style=&quot;border-left: 1px solid #ccc;&quot;&gt;
      +
    &lt;/button&gt;
  &lt;/div&gt;
&lt;/div&gt;

huangapple
  • 本文由 发表于 2023年3月31日 18:24:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/75897443.html
匿名

发表评论

匿名网友

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

确定