简体   繁体   English

使用不同大小的antD Modal

[英]Use different sizes of antD Modal

I'm using antD modal to show an editor, the popup window should be fixed size to prevent size changing when collapsing/expanding sections inside.我正在使用 antD 模态显示编辑器,弹出窗口 window 应该是固定大小,以防止在内部折叠/展开部分时改变大小。

So I customized:所以我定制了:

.ant-modal-content {
max-height: 700px;
height: 700px;
width: 1000px;
/*overflow-y: auto;*/
/*overflow-x: auto;*/

} }

but it's affecting other popups!但它会影响其他弹出窗口! I tried using style={{height: '700px', width: '1000px'}} of that specific modal but it didn't take affect.我尝试使用该特定模式style={{height: '700px', width: '1000px'}}但它没有生效。

How can I control the size of only one modal?我怎样才能控制只有一个模态的大小?

Sandbox: https://codesandbox.io/s/antd-reproduction-template-ci559?file=/index.css沙盒: https://codesandbox.io/s/antd-reproduction-template-ci559?file=/index.css

(try to change the size o the syntax textarea as example for changing the size) (尝试更改语法文本区域的大小作为更改大小的示例)

CSS styles defined in index.css file are global styles, meaning they affect every element/component in each file. CSS styles 定义在索引中index.css文件是全局 ZBC4150D023D3255136DB671DZ61AC9 中的每个元素/组件。

If you want to apply some styles on a specific element/component, you have 2 options:如果您想在特定元素/组件上应用一些 styles,您有 2 个选项:

  1. use CSS Modules .使用CSS 模块 They allow you to restrict styles to specific component and reuse class names without worrying about name clashes or css styles affecting other components or element.它们允许您将 styles 限制为特定组件并重用 class 名称,而无需担心名称冲突或 css ZBC4150D023D3253F26 影响其他组件的其他组件。

  2. As your popup window is a div element with a class named wrapper , apply the styles on wrapper class in RuleEditor.css file As your popup window is a div element with a class named wrapper , apply the styles on wrapper class in RuleEditor.css file

     .wrapper { max-height: 400px; }

but keep in mind that if you use wrapper class somewhere else, these styles will affect those components/elements as well.但请记住,如果您在其他地方使用包装器 class,这些 styles 也会影响这些组件/元素。

you also have to prevent textarea from resizing as well otherwise it will overflow.您还必须防止textarea调整大小,否则它会溢出。 To do this, inside RuleEditor.js file, change the styles applied on TextArea component from为此,在RuleEditor.js文件中,将应用于TextArea组件的 styles 从

style={{ width: "100%", resize: "auto" }}

to

style={{ width: "100%", resize: "none" }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM