admin管理员组文章数量:1313187
Im using this
export function notificationWithIcon(type, title, description, placement) {
notification[type]({
message: title,
description: description,
placement
});
}
However, the only options are topRight, bottomRight, bottomLeft or topLeft
I would like it to appear in the center of my screen. Is there any way to achieve that
EDIT: I used Majid's idea and this is how it looks like now. It's still positioned a bit to the right
Im using this
export function notificationWithIcon(type, title, description, placement) {
notification[type]({
message: title,
description: description,
placement
});
}
However, the only options are topRight, bottomRight, bottomLeft or topLeft
I would like it to appear in the center of my screen. Is there any way to achieve that
EDIT: I used Majid's idea and this is how it looks like now. It's still positioned a bit to the right
Share Improve this question edited Feb 10, 2022 at 8:17 Marko Marchisio asked Feb 9, 2022 at 8:23 Marko MarchisioMarko Marchisio 4973 gold badges12 silver badges20 bronze badges 1-
You mean you want to show notification in the
[top|bottom]-center
or 'center-center'? – Saeed Shamloo Commented Feb 9, 2022 at 8:42
2 Answers
Reset to default 4Based on documentations:
A notification box can appear from the topRight, bottomRight, bottomLeft or topLeft of the viewport.
But you can customize it yourself with css classes
:
.ant-notification-center {
left: 50%;
bottom: 50% !important;
margin-right: 30%;
transform: translate(-50%, -50%);
}
and use the notification
same as following sample:
import React from "react";
import ReactDOM from "react-dom";
import "antd/dist/antd.css";
import "./index.css";
import { Button, notification, Space } from "antd";
import { RadiusUpleftOutlined } from "@ant-design/icons";
const openNotification = (placement) => {
notification.info({
message: `Notification ${placement}`,
duration: 10000,
description:
"This is the content of the notification. This is the content of the notification. This is the content of the notification.",
placement
});
};
ReactDOM.render(
<div>
<Space>
<Button type="primary" onClick={() => openNotification("center")}>
<RadiusUpleftOutlined />
center
</Button>
</Space>
</div>,
document.getElementById("container")
);
You can set your notification as
const [api, contextHolder] = notification.useNotification();
and then call it as shown below:
api.info({
message: `Notification`,
description: 'bla bla bla',
placement: 'top',
});
by default it should be centered if you didn't override antd css style.
try it in my CodeSandbox
P.S. You also might be interested in antd message
本文标签: javascriptHow to position antd notificationi want it to be centeredStack Overflow
版权声明:本文标题:javascript - How to position antd notification - i want it to be centered - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741920799a2404991.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论