英文:
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 :
<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>
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;
}
}
最终输出:
英文:
You can consider using arbitary value if you want to have 1px in only one side of the div
<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>
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="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
}
Final Output:
答案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;
<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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论