学习Tailwind CSS,试图找出将SVG图标移动到按钮右上角的正确方法是什么?这与Github上的通知行为相似,当查看他们使用的代码时
:before
.申请
top-0
和
inset-y-0
移动了
div
到布局的顶部。
研究
尝试
BtnIcon组件:
import React, {FC, ElementType, ReactNode} from 'react'
interface Props {
label: string
Icon: ElementType
children: ReactNode
}
const IconBtn: FC<Props> = ({label, Icon, children}) => {
return (
<button
type="button"
aria-label={label}
className="group flex items-center p-2 hover:bg-secondary-50 transition-colors rounded-md cursor-pointer"
>
<Icon className="h-6 w-6 flex-shrink-0 text-secondary-500 group-hover:text-secondary-800" />
{children}
</button>
)
}
export default IconBtn
孩子:
<Link href="/">
<div className="flex justify-center items-center">
<IconBtn label="foo" Icon={NotificationIcon}>
<span className="sr-only">notification</span>
<div className="relative">
<div
aria-labelledby="notification-tooltip"
className="absolute top-0 right-0 w-2 h-2 bg-red-700 rounded-full"
></div>
</div>
</IconBtn>
</div>
</Link>