在tailwindcss中,我用两个按钮Cancel和Save right aligned创建了页脚:
<div class="p-2 flex">
<div class="w-1/2">Empty Space</div>
<div class="w-1/2">
<button type="submit" class="bg-gray-500 text-white p-2 rounded text-sm w-auto float-right">
Cancel
</button>
<button type="submit" class="bg-yellow-500 text-white p-2 ml-6 rounded text-lg w-auto float-right ">
Save
</button>
</div>
</div>
它可以工作,但我需要不同的:在保存后立即取消对齐,而不是像我需要的那样取消对齐。
哪种方式是正确的?
谢谢!
发布于 2021-02-09 22:46:46
float-right
将从右向左放置元素,因此您只需切换取消和保存按钮的顺序:
<div class="p-2 flex">
<div class="w-1/2">Empty Space</div>
<div class="w-1/2">
<button type="submit" class="bg-yellow-500 text-white p-2 ml-6 rounded text-lg w-auto float-right ">
Save
</button>
<button type="submit" class="bg-gray-500 text-white p-2 rounded text-sm w-auto float-right">
Cancel
</button>
</div>
</div>
发布于 2021-02-10 07:27:10
与使用float-right
相比,我更喜欢在父元素中使用flex justify-end
<div class="p-2 flex">
<div class="w-1/2">Empty Space</div>
<div class="w-1/2 flex justify-end">
<button type="submit" class="bg-gray-500 text-white p-2 rounded text-sm w-auto">
Cancel
</button>
<button type="submit" class="bg-yellow-500 text-white p-2 ml-6 rounded text-lg w-auto">
Save
</button>
</div>
</div>
下面是一个使用Tailwind Play的示例
https://stackoverflow.com/questions/66119330
复制相似问题