第一部分: 前言

 推荐网站: https://ant.design/docs/spec/introduce-cn

  ant.design是基于react开发的一个解放ui和前端的工具,它提供了一致的设计方便我们快速开发和减少不必要的设计与代码,很多实用react框架的开发者都已经在使用ant.design了,且其在github上的star数也早已上万,足见其火热程度。

  ant.design的目的也在于提高用户、开发者等多方的体验与幸福感。

  

  ant.design设计很精妙,vue的iview就是模仿ant.design来实现的。

  

  

  既然要使用ant.design,我们不妨了解其设计原则是否是我们想要的,对于设计,我了解的最多的便是对比、对齐、亲密性、重复性,而ant.design也很好的实现了这些规则,并在此基础山践行了更多的想法。

  • 直接了当  『需要在哪里输出,就要允许在哪里输入』。这就是直接操作的原理。eg:不要为了编辑内容而打开另一个页面,应该直接在上下文中实现编辑。
  • 足不出户
  • 简化交互 --- 如悬停时出现工具,qq在这里做的很好。
  • 提供邀请
  • 巧用过渡

  https://ant.design/docs/spec/colors-cn

第二部分: 使用(引入css不好的方法)

  ant.design 使用起来非常简单。

  第一步:

  1. npm install antd --save

  

  第二步(选择性的):

将node_modules下面的dist下面的 antd.min.css 取出放在静态文件中,在head中link引入。

  第三步,开始使用:

在某个组件的上方:

  1. import {message} from 'antd'

然后在需要的时候使用: message.error('错误'); message.success('登录成功!'); 类似的使用即可。

 

  如果我们仅仅是js,css完全自己写,那么上面的就足够了,但是,如果我们希望使用 ant.design 提供的css,那么我们就需要把css文件取出放在静态文件中,并在html的head中引用了。 

  注意: 在使用的时候引入的css中还使用了css初始化,如下所示:

  1. * antd v2.12.3
  2. *
  3. * Copyright -present, Alipay, Inc.
  4. * All rights reserved.
  5. */
  6. /*! normalize.css v7.0.0 | MIT License | github.com/necolas/normalize.css */
  7. /* Document
  8. ========================================================================== */
  9. /**
  10. * 1. Correct the line height in all browsers.
  11. * 2. Prevent adjustments of font size after orientation changes in
  12. * IE on Windows Phone and in iOS.
  13. */
  14. html {
  15. line-height: 1.15;
  16. /* 1 */
  17. -ms-text-size-adjust: %;
  18. /* 2 */
  19. -webkit-text-size-adjust: %;
  20. /* 2 */
  21. }
  22. /* Sections
  23. ========================================================================== */
  24. /**
  25. * Remove the margin in all browsers (opinionated).
  26. */
  27. body {
  28. margin: ;
  29. }
  30. /**
  31. * Add the correct display in IE 9-.
  32. */
  33. article,
  34. aside,
  35. footer,
  36. header,
  37. nav,
  38. section {
  39. display: block;
  40. }
  41. /**
  42. * Correct the font size and margin on `h1` elements within `section` and
  43. * `article` contexts in Chrome, Firefox, and Safari.
  44. */
  45. h1 {
  46. font-size: 2em;
  47. margin: .67em ;
  48. }
  49. /* Grouping content
  50. ========================================================================== */
  51. /**
  52. * Add the correct display in IE 9-.
  53. * 1. Add the correct display in IE.
  54. */
  55. figcaption,
  56. figure,
  57. main {
  58. /* 1 */
  59. display: block;
  60. }
  61. /**
  62. * Add the correct margin in IE 8.
  63. */
  64. figure {
  65. margin: 1em 40px;
  66. }
  67. /**
  68. * 1. Add the correct box sizing in Firefox.
  69. * 2. Show the overflow in Edge and IE.
  70. */
  71. hr {
  72. box-sizing: content-box;
  73. /* 1 */
  74. height: ;
  75. /* 1 */
  76. overflow: visible;
  77. /* 2 */
  78. }
  79. /**
  80. * 1. Correct the inheritance and scaling of font size in all browsers.
  81. * 2. Correct the odd `em` font sizing in all browsers.
  82. */
  83. pre {
  84. font-family: monospace, monospace;
  85. /* 1 */
  86. /* stylelint-disable-line */
  87. font-size: 1em;
  88. /* 2 */
  89. }
  90. /* Text-level semantics
  91. ========================================================================== */
  92. /**
  93. * 1. Remove the gray background on active links in IE 10.
  94. * 2. Remove gaps in links underline in iOS 8+ and Safari 8+.
  95. */
  96. a {
  97. background-color: transparent;
  98. /* 1 */
  99. -webkit-text-decoration-skip: objects;
  100. /* 2 */
  101. }
  102. /**
  103. * 1. Remove the bottom border in Chrome 57- and Firefox 39-.
  104. * 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.
  105. */
  106. abbr[title] {
  107. border-bottom: none;
  108. /* 1 */
  109. text-decoration: underline;
  110. /* 2 */
  111. text-decoration: underline dotted;
  112. /* 2 */
  113. }
  114. /**
  115. * Prevent the duplicate application of `bolder` by the next rule in Safari 6.
  116. */
  117. b,
  118. strong {
  119. font-weight: inherit;
  120. }
  121. /**
  122. * Add the correct font weight in Chrome, Edge, and Safari.
  123. */
  124. b,
  125. strong {
  126. font-weight: bolder;
  127. }
  128. /**
  129. * 1. Correct the inheritance and scaling of font size in all browsers.
  130. * 2. Correct the odd `em` font sizing in all browsers.
  131. */
  132. code,
  133. kbd,
  134. samp {
  135. font-family: monospace, monospace;
  136. /* 1 */
  137. /* stylelint-disable-line */
  138. font-size: 1em;
  139. /* 2 */
  140. }
  141. /**
  142. * Add the correct font style in Android 4.3-.
  143. */
  144. dfn {
  145. font-style: italic;
  146. }
  147. /**
  148. * Add the correct background and color in IE 9-.
  149. */
  150. mark {
  151. background-color: #ff0;
  152. color: #;
  153. }
  154. /**
  155. * Add the correct font size in all browsers.
  156. */
  157. small {
  158. font-size: %;
  159. }
  160. /**
  161. * Prevent `sub` and `sup` elements from affecting the line height in
  162. * all browsers.
  163. */
  164. sub,
  165. sup {
  166. font-size: %;
  167. line-height: ;
  168. position: relative;
  169. vertical-align: baseline;
  170. }
  171. sub {
  172. bottom: -.25em;
  173. }
  174. sup {
  175. top: -.5em;
  176. }
  177. /* Embedded content
  178. ========================================================================== */
  179. /**
  180. * Add the correct display in IE 9-.
  181. */
  182. audio,
  183. video {
  184. display: inline-block;
  185. }
  186. /**
  187. * Add the correct display in iOS 4-7.
  188. */
  189. audio:not([controls]) {
  190. display: none;
  191. height: ;
  192. }
  193. /**
  194. * Remove the border on images inside links in IE 10-.
  195. */
  196. img {
  197. border-style: none;
  198. }
  199. /**
  200. * Hide the overflow in IE.
  201. */
  202. svg:not(:root) {
  203. overflow: hidden;
  204. }
  205. /* Forms
  206. ========================================================================== */
  207. /**
  208. * 1. Change the font styles in all browsers (opinionated).
  209. * 2. Remove the margin in Firefox and Safari.
  210. */
  211. button,
  212. input,
  213. optgroup,
  214. select,
  215. textarea {
  216. font-family: sans-serif;
  217. /* 1 */
  218. font-size: %;
  219. /* 1 */
  220. line-height: 1.15;
  221. /* 1 */
  222. margin: ;
  223. /* 2 */
  224. }
  225. /**
  226. * Show the overflow in IE.
  227. * 1. Show the overflow in Edge.
  228. */
  229. button,
  230. input {
  231. /* 1 */
  232. overflow: visible;
  233. }
  234. /**
  235. * Remove the inheritance of text transform in Edge, Firefox, and IE.
  236. * 1. Remove the inheritance of text transform in Firefox.
  237. */
  238. button,
  239. select {
  240. /* 1 */
  241. text-transform: none;
  242. }
  243. /**
  244. * 1. Prevent a WebKit bug where (2) destroys native `audio` and `video`
  245. * controls in Android 4.
  246. * 2. Correct the inability to style clickable types in iOS and Safari.
  247. */
  248. button,
  249. html [type="button"],
  250. [type="reset"],
  251. [type="submit"] {
  252. -webkit-appearance: button;
  253. /* 2 */
  254. }
  255. /**
  256. * Remove the inner border and padding in Firefox.
  257. */
  258. button::-moz-focus-inner,
  259. [type="button"]::-moz-focus-inner,
  260. [type="reset"]::-moz-focus-inner,
  261. [type="submit"]::-moz-focus-inner {
  262. border-style: none;
  263. padding: ;
  264. }
  265. /**
  266. * Restore the focus styles unset by the previous rule.
  267. */
  268. button:-moz-focusring,
  269. [type="button"]:-moz-focusring,
  270. [type="reset"]:-moz-focusring,
  271. [type="submit"]:-moz-focusring {
  272. outline: 1px dotted ButtonText;
  273. }
  274. /**
  275. * Correct the padding in Firefox.
  276. */
  277. fieldset {
  278. padding: .35em .75em .625em;
  279. }
  280. /**
  281. * 1. Correct the text wrapping in Edge and IE.
  282. * 2. Correct the color inheritance from `fieldset` elements in IE.
  283. * 3. Remove the padding so developers are not caught out when they zero out
  284. * `fieldset` elements in all browsers.
  285. */
  286. legend {
  287. box-sizing: border-box;
  288. /* 1 */
  289. color: inherit;
  290. /* 2 */
  291. display: table;
  292. /* 1 */
  293. max-width: %;
  294. /* 1 */
  295. padding: ;
  296. /* 3 */
  297. white-space: normal;
  298. /* 1 */
  299. }
  300. /**
  301. * 1. Add the correct display in IE 9-.
  302. * 2. Add the correct vertical alignment in Chrome, Firefox, and Opera.
  303. */
  304. progress {
  305. display: inline-block;
  306. /* 1 */
  307. vertical-align: baseline;
  308. /* 2 */
  309. }
  310. /**
  311. * Remove the default vertical scrollbar in IE.
  312. */
  313. textarea {
  314. overflow: auto;
  315. }
  316. /**
  317. * 1. Add the correct box sizing in IE 10-.
  318. * 2. Remove the padding in IE 10-.
  319. */
  320. [type="checkbox"],
  321. [type="radio"] {
  322. box-sizing: border-box;
  323. /* 1 */
  324. padding: ;
  325. /* 2 */
  326. }
  327. /**
  328. * Correct the cursor style of increment and decrement buttons in Chrome.
  329. */
  330. [type="number"]::-webkit-inner-spin-button,
  331. [type="number"]::-webkit-outer-spin-button {
  332. height: auto;
  333. }
  334. /**
  335. * 1. Correct the odd appearance in Chrome and Safari.
  336. * 2. Correct the outline style in Safari.
  337. */
  338. [type="search"] {
  339. -webkit-appearance: textfield;
  340. /* 1 */
  341. outline-offset: -2px;
  342. /* 2 */
  343. }
  344. /**
  345. * Remove the inner padding and cancel buttons in Chrome and Safari on macOS.
  346. */
  347. [type="search"]::-webkit-search-cancel-button,
  348. [type="search"]::-webkit-search-decoration {
  349. -webkit-appearance: none;
  350. }
  351. /**
  352. * 1. Correct the inability to style clickable types in iOS and Safari.
  353. * 2. Change font properties to `inherit` in Safari.
  354. */
  355. ::-webkit-file-upload-button {
  356. -webkit-appearance: button;
  357. /* 1 */
  358. font: inherit;
  359. /* 2 */
  360. }
  361. /* Interactive
  362. ========================================================================== */
  363. /*
  364. * Add the correct display in IE 9-.
  365. * 1. Add the correct display in Edge, IE, and Firefox.
  366. */
  367. details,
  368. menu {
  369. display: block;
  370. }
  371. /*
  372. * Add the correct display in all browsers.
  373. */
  374. summary {
  375. display: list-item;
  376. }
  377. /* Scripting
  378. ========================================================================== */
  379. /**
  380. * Add the correct display in IE 9-.
  381. */
  382. canvas {
  383. display: inline-block;
  384. }
  385. /**
  386. * Add the correct display in IE.
  387. */
  388. template {
  389. display: none;
  390. }
  391. /* Hidden
  392. ========================================================================== */
  393. /**
  394. * Add the correct display in IE 10-.
  395. */
  396. [hidden] {
  397. display: none;
  398. }
  399. @font-face {
  400. font-family: "Helvetica Neue For Number";
  401. src: local("Helvetica Neue");
  402. unicode-range: U+-;
  403. }
  404. * {
  405. box-sizing: border-box;
  406. -webkit-tap-highlight-color: rgba(, , , );
  407. }
  408. *:before,
  409. *:after {
  410. box-sizing: border-box;
  411. }
  412. html,
  413. body {
  414. width: %;
  415. height: %;
  416. }
  417. body {
  418. font-family: "Helvetica Neue For Number", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
  419. font-size: 12px;
  420. line-height: 1.5;
  421. color: rgba(, , , 0.65);
  422. background-color: #fff;
  423. }
  424. body,
  425. div,
  426. dl,
  427. dt,
  428. dd,
  429. ul,
  430. ol,
  431. li,
  432. h1,
  433. h2,
  434. h3,
  435. h4,
  436. h5,
  437. h6,
  438. pre,
  439. code,
  440. form,
  441. fieldset,
  442. legend,
  443. input,
  444. textarea,
  445. p,
  446. blockquote,
  447. th,
  448. td,
  449. hr,
  450. button,
  451. article,
  452. aside,
  453. details,
  454. figcaption,
  455. figure,
  456. footer,
  457. header,
  458. hgroup,
  459. menu,
  460. nav,
  461. section {
  462. margin: ;
  463. padding: ;
  464. }
  465. button,
  466. input,
  467. select,
  468. textarea {
  469. font-family: inherit;
  470. font-size: inherit;
  471. line-height: inherit;
  472. color: inherit;
  473. }
  474. ul,
  475. ol {
  476. list-style: none;
  477. }
  478. input::-ms-clear,
  479. input::-ms-reveal {
  480. display: none;
  481. }
  482. ::-moz-selection {
  483. background: #108ee9;
  484. color: #fff;
  485. }
  486. ::selection {
  487. background: #108ee9;
  488. color: #fff;
  489. }
  490. h1,
  491. h2,
  492. h3,
  493. h4,
  494. h5,
  495. h6 {
  496. color: rgba(, , , 0.85);
  497. font-weight: ;
  498. }
  499. a {
  500. color: #108ee9;
  501. background: transparent;
  502. text-decoration: none;
  503. outline: none;
  504. cursor: pointer;
  505. -webkit-transition: color .3s ease;
  506. transition: color .3s ease;
  507. }
  508. a:focus {
  509. text-decoration: underline;
  510. -webkit-text-decoration-skip: ink;
  511. text-decoration-skip: ink;
  512. }
  513. a:hover {
  514. color: #49a9ee;
  515. }
  516. a:active {
  517. color: #0e77ca;
  518. }
  519. a:active,
  520. a:hover {
  521. outline: ;
  522. text-decoration: none;
  523. }
  524. a[disabled] {
  525. color: rgba(, , , 0.25);
  526. cursor: not-allowed;
  527. pointer-events: none;
  528. }

  

   其实,有些时候,使用 ant.design 没有办法满足我们的样式要求,所以,我们就需要使用 !important 来先找到样式然后强制来覆盖,但这绝对不是最佳实践。 

   下面我们介绍一种比较好用的方法。 

第三部分: 使用(引入CSS较好的做法)、解析

  之前我们引入css的方式是直接把整个css文件引入,这时一种不好的做法,因为在一个项目中也许我们仅仅是使用其中的几个组件,所以引入所有的css是完全没有必要的。

  那么解决办法是什么呢?

  拿 message 举例,我们可以在node_modules下的antd下的message中看到如下结构:

  即,这里不仅仅有 index.js 和 index.d.ts 两者构成的js组件,还有一个 style 文件夹,这个文件夹中描述了对组件的样式。我们是可以直接从这里引入的。

  

  比如,我们需要引入 message 的组件和相关的css,可以像下面这样:

  1. import { message } from 'antd';
  2. require('antd/lib/message/style')

  当然也可以不用require, 用 import 也是可以的,如下所示:

  1. import { message } from 'antd';
  2. import 'antd/lib/message/style'

  

  对于第一条语句,很容易理解,即引入了message的js组件。

  对于第二条语句,由于 style 是一个文件夹,根据规则,是默认寻找其中的 index.js ,我们看看 index.js 中的内容是什么?

  1. 'use strict';
  2.  
  3. require('../../style/index.less');
  4.  
  5. require('./index.less');

  其中的 ../../style/index.less 是ant.design的主题配置,比如,我们可以配置它的整体的颜色、文字大小等等。

  另外,就是引入了这个style下面的 index.less, 比如message下的less是这样的:

  1. @import "../../style/themes/default";
  2.  
  3. @message-prefix-cls: ~"@{ant-prefix}-message";
  4.  
  5. .@{message-prefix-cls} {
  6. font-size: 16px;
  7. position: fixed;
  8. z-index: @zindex-message;
  9. width: %;
  10. top: 0px;
  11. left: ;
  12. pointer-events: none;
  13.  
  14. &-notice {
  15. padding: 16px;
  16. padding-top: 16px;
  17. text-align: center;
  18. &:first-child {
  19. margin-top: -8px;
  20. }
  21. }
  22.  
  23. &-notice-content {
  24. padding: 16px 32px;
  25. border-radius: @border-radius-base;
  26. box-shadow: @shadow-;
  27. background: @component-background;
  28. display: inline-block;
  29. pointer-events: all;
  30. }
  31.  
  32. &-success .@{iconfont-css-prefix} {
  33. color: @success-color;
  34. }
  35.  
  36. &-error .@{iconfont-css-prefix} {
  37. color: @error-color;
  38. }
  39.  
  40. &-warning .@{iconfont-css-prefix} {
  41. color: @warning-color;
  42. }
  43.  
  44. &-info .@{iconfont-css-prefix},
  45. &-loading .@{iconfont-css-prefix} {
  46. color: @info-color;
  47. }
  48.  
  49. .@{iconfont-css-prefix} {
  50. margin-right: 8px;
  51. font-size: @font-size-lg;
  52. top: 1px;
  53. position: relative;
  54. }
  55.  
  56. &-notice.move-up-leave.move-up-leave-active {
  57. animation-name: MessageMoveOut;
  58. overflow: hidden;
  59. animation-duration: .3s;
  60. }
  61. }
  62.  
  63. @keyframes MessageMoveOut {
  64. % {
  65. opacity: ;
  66. max-height: 150px;
  67. padding: 8px;
  68. }
  69. % {
  70. opacity: ;
  71. max-height: ;
  72. padding: ;
  73. }
  74. }

  

  我们如果觉得样式不合适,只需要在这个less文件中直接修改就可以了。这样就会经过编译在页面上显示出效果。

  那么其中的js文件又代表什么呢? 即一个是 index.js, 另外一个是 index.d.js,这两个文件就描述了这个 message 组件。 我们首先来看看 index.js 内容吧,直接在代码中注释解释:'use strict';// 这句声明表示这个文件是一个可以被引入的模块。

  1. Object.defineProperty(exports, "__esModule", {
  2. value: true
  3. });

  4. // 引入react
  5. var _react = require('react');
  6. var _react2 = _interopRequireDefault(_react);

  7. // 引入 rcNotification
  8. var _rcNotification = require('rc-notification');
  9. var _rcNotification2 = _interopRequireDefault(_rcNotification);

  10. // 引入 icon 组件,即通知正确、错误时的图标icon
  11. var _icon = require('../icon');
  12. var _icon2 = _interopRequireDefault(_icon);
  13. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

  14. // 通知的toast默认时间设置为3s
  15. var defaultDuration = 3;
  16. // 这里的void后面可以是一个表达式,但是这个表达式的返回结果永远是undefined。
  17. var defaultTop = void ;
  18. var messageInstance = void ;
  19. var key = ;
  20. // 这里应该是组件的前缀
  21. var prefixCls = 'ant-message';
  22. var getContainer = void ;
  23. // 获取一个 message 实例
  24. function getMessageInstance() {
  25. messageInstance = messageInstance || _rcNotification2['default'].newInstance({
  26. prefixCls: prefixCls,
  27. transitionName: 'move-up',
  28. style: { top: defaultTop },
  29. getContainer: getContainer
  30. });
  31. return messageInstance;
  32. }
  33. function notice(content) {
  34. var duration = arguments.length > && arguments[] !== undefined ? arguments[] : defaultDuration;
  35. var type = arguments[];
  36. var onClose = arguments[];

  37.   // 定义icon的样式
  38. var iconType = {
  39. info: 'info-circle',
  40. success: 'check-circle',
  41. error: 'cross-circle',
  42. warning: 'exclamation-circle',
  43. loading: 'loading'
  44. }[type];
      
      // 在notice(通知)的时候创建一个实例
    var instance = getMessageInstance();
  45. instance.notice({
  46. key: key,
  47. duration: duration,
  48. style: {},
  49. content: _react2['default'].createElement(
  50. 'div',
  51. { className: prefixCls + '-custom-content ' + prefixCls + '-' + type },
  52. _react2['default'].createElement(_icon2['default'], { type: iconType }),
  53. _react2['default'].createElement(
  54. 'span',
  55. null,
  56. content
  57. )
  58. ),
  59. onClose: onClose
  60. });
  61. return function () {
  62. var target = key++;
  63. return function () {
  64. instance.removeNotice(target);
  65. };
  66. }();
  67. }
  68. // 关键: 暴露出去的方法,就是我们在组件中引入message时可以直接调用的方法。
  69. exports['default'] = {
  70. info: function info(content, duration, onClose) {
  71. return notice(content, duration, 'info', onClose);
  72. },
  73. success: function success(content, duration, onClose) {
  74. return notice(content, duration, 'success', onClose);
  75. },
  76. error: function error(content, duration, onClose) {
  77. return notice(content, duration, 'error', onClose);
  78. },
  79. // Departed usage, please use warning()
  80. warn: function warn(content, duration, onClose) {
  81. return notice(content, duration, 'warning', onClose);
  82. },
  83. warning: function warning(content, duration, onClose) {
  84. return notice(content, duration, 'warning', onClose);
  85. },
  86. loading: function loading(content, duration, onClose) {
  87. return notice(content, duration, 'loading', onClose);
  88. },
  89. config: function config(options) {
  90. if (options.top !== undefined) {
  91. defaultTop = options.top;
  92. messageInstance = null; // delete messageInstance for new defaultTop
  93. }
  94. if (options.duration !== undefined) {
  95.   = options.duration;
  96. }
  97. if (options.prefixCls !== undefined) {
  98. prefixCls = options.prefixCls;
  99. }
  100. if (options.getContainer !== undefined) {
  101. getContainer = options.getContainer;
  102. }
  103. },
  104. destroy: function destroy() {
  105. if (messageInstance) {
  106. messageInstance.destroy();
  107. messageInstance = null;
  108. }
  109. }
  110. };
  111. module.exports = exports['default'];

  可以看到,这些方法,如 message.info() 、message.warning()都可以接收三个参数

  • 希望通知的信息
  • 这个通知信息所持续的时间
  • 当通知结束之后的回调函数

   ok!下面我们来看看 index.d.ts 文件:

  1. /// <reference types="react" />
  2. import React from 'react';
  3. export declare type ConfigOnClose = () => void;
  4. export interface ConfigOptions {
  5. top?: number;
  6. duration?: number;
  7. prefixCls?: string;
  8. getContainer?: () => HTMLElement;
  9. }
  10. declare const _default: {
  11. info(content: React.ReactNode, duration?: number | undefined, onClose?: ConfigOnClose | undefined): () => void;
  12. success(content: React.ReactNode, duration?: number | undefined, onClose?: ConfigOnClose | undefined): () => void;
  13. error(content: React.ReactNode, duration?: number | undefined, onClose?: ConfigOnClose | undefined): () => void;
  14. warn(content: React.ReactNode, duration?: number | undefined, onClose?: ConfigOnClose | undefined): () => void;
  15. warning(content: React.ReactNode, duration?: number | undefined, onClose?: ConfigOnClose | undefined): () => void;
  16. loading(content: React.ReactNode, duration?: number | undefined, onClose?: ConfigOnClose | undefined): () => void;
  17. config(options: ConfigOptions): void;
  18. destroy(): void;
  19. };
  20. export default _default;

 

  哈哈 ,看不懂,等看完了ts回来讲解。

  

第四部分: ant.design的栅格系统

  在 ant.design 中,对于栅格系统的设计和bootstrap中的设计是极其类似的,核心概念为: Row一定是最外层的, Col一定是分布在Row中的, 内容一定是在Col里的, 当然,在Col中我们还可以嵌套Row,在antd中, Col被分成了24分(与bootstrap的12份是类似的)。 

  在Col中,我们可以使用span={number}来制定一个Col的宽度,具体的做法是使用 百分比 来划分, 如 span={4} 的占满,那么每一份就是 16.6667% , 如果 span={12} 占满,那么每一份就是 50%。。。。 依次类推。 

  另外,在Col中我们还可以使用offset来进行便宜,正值为向右偏移,使用的原理是 margin-left 或者是 margin-right。 

  我们还可以在Row中设置 gutter={number } 这个值就是栅格的间距,具体实现原理就是对div根据百分比来划分,然后在div内容使用padding,这时content肯定是减小的。 

     除此之外,还可以在 Col 中设置 push={number} 以及 pull={number},实现原理也非常简单,就是使用元素的 position: relative;值,通过 left=百分比;以及right=百分比; 这样就可以实现pull 和 push 就可以了。 

  

  当然,我们还可以使用 Row 的flex进行布局,这种布局方式只需要在 Row 上设置 type="flex",就可以设置竖直和水平对齐方式了。 

  竖直对齐方式:

  • align="top" 向上对齐
  • align="middle" 中间对齐
  • alegn="bottom" 向下对齐

  水平对其方式:

  • justify="start" 左对齐
  • justify='end' 右对齐
  • justify="center" 中间对齐
  • justify='space-between' 中间
  • jusify="space-around" 中间

  

  这些flex布局的原理也很简单,就是直接使用css3的flex, 如align-items以及 justify-content。

  

  另外, ant.design也是支持响应式布局的 。 和bootstrap一样。

  注意点:

  • 一般在我们制作表格的时候,可以使用 ant.design 的栅格系统,比如,左边是说明性文字,右边是选择项或者是input框。 整体使用flex布局即可。 左边的给一个固定的宽度,如span={4},右边的就是span={24}了, 并且在右边,如果是input框就比较好解决,如果是几个框,我们需要分开排列,就需要使用一个 <Row>,然后设置flex,其中justify应该是space-between,而能是start、end、center或者是 space-around。 因为对于 start、end、center,会使得几个框都会贴的很紧(除非是我们在其中再添加一个div,然后添加一个padding,这样才能做到分割),那么space-between和space-around的区别是什么?前者是两边贴近然后中间有空位置,而后者是两边的距离为中间padding的一般。 
  • 另外,我们也是可以用gutter的,但是最好不用,因为,gutter在两边也会有间距,这样对于对齐的控制非常麻烦。

ant.design初探的更多相关文章

  1. 初探ant design pro

    1.增加路由子页面&配置菜单 因为ant design pro采取的是umi路由配置,所以只要在对应的文件夹下新建相关的文件夹以及文件,它会自动解析.按照如下的步骤做即可 PS.如果想要给菜单 ...

  2. Ant Design 的一个练习小Demo

    Ant Design 由蚂蚁金服团队出品, 基于 React 的组件化开发模式,封装了一套丰富而实用的 UI 组件库. 在这个练习Demo 中,按照 Ant Design 官网的教程示例,尝试使用 A ...

  3. 实现Ant Design 自定义表单组件

    Ant Design 组件提供了Input,InputNumber,Radio,Select,uplod等表单组件,但实际开发中这是不能满足需求,同时我们希望可以继续使用Form提供的验证和提示等方法 ...

  4. Ant Design UI组件

    Ant Design 是面向中台的 UI 设计语言.  http://ant.design/

  5. Ant Design Pro+Electron+electron-builder实现React应用脱离浏览器,桌面安装运行

    ant-design-pro ----> version :2.3.1 由于网上Ant Design Pro+Electron的资料太少,我就贡献一点经验   最近需要讲AntD Pro项目(以 ...

  6. button样式篇一(ant Design React)

    这篇来介绍button中elementUi.iview.ant中样式结构 ant Design react ant-react中button分两个文件less: mixins.less:根据butto ...

  7. elementUi、iview、ant Design源码button结构篇

    在看elementUI的button组件的时候,一起和iview.ant Design的button组件比 较功能.样式.代码结构,看他们的一些不同点,不同的写法哪种会好些,button的对外开放的功 ...

  8. 使用selenium操作ant design前端的页面,感觉页面没加载完

    因需要收集页面数据,遂准备使用selenium爬取瓦斯阅读页面, 瓦斯网站使用的是ant design,元素定位非常困难,页面元素都没有ID,现在还只是能做到操作登录,不能自动打开订阅,查询某公众号, ...

  9. 使用Ant Design的select组件时placeholder不生效/不起作用的解决办法

    先来说说使用Ant Design和Element-ui的感觉吧. 公司的项目开发中用的是vue+element-ui,使用了一通下来后,觉得element-ui虽然也有一些问题或坑,但这些小问题或坑凭 ...

随机推荐

  1. 使用 console.time() 计算js代码执行时间

    console.time('hellor'); for(var i=0;i<100000;i++){} console.timeEnd('hellor');

  2. linux 管道与重定向

    命令行shell数据流有如下定义: 通过管道和重定向可以控制CLI的数据流

  3. JAVA IO总结及socket简单实现

    为了方便理解与阐述,先引入两张图: a.Java IO中常用的类 在整个Java.io包中最重要的就是5个类和一个接口.5个类指的是File.OutputStream.InputStream.Writ ...

  4. ASP.NET程序从IIS6移植到IIS7时出现500.22错误(转)

    最可能的原因: •    此应用程序在 system.web/httpModules 节中定义配置. 可尝试的操作: •    将配置迁移到 system.webServer/modules 节.也可 ...

  5. 创建oracle数据库时,出现ORA-00922: 选项缺失或无效

    sdd53HOME 新建oracle数据库时遇到ORA-00922: 选项缺失或无效的问题,如图: 原因:一般是语句的语法有问题.比如命名不对,关键字写错等等.对于非标准的命名,一般采用双引号来创建. ...

  6. 201621123023《Java程序设计》第2周学习总结

    一. 本周学习总结 引用类型变量存放指向对象的引用(类似于地址): == 与 equals 区别在于:==比较的是引用是否相等, 而equals则比较指向对象的内容是否相等: 因为String的不可变 ...

  7. “全栈2019”Java第二十二章:控制流程语句中的决策语句if-else

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  8. bzoj1800飞行棋

    题目链接 简单模拟 真的不敢相信ahoi09年的题竟然是这个难度 首先,一个必须要知道的定理是:圆上只有直径所对的圆周角是直角. 然后就很显然了, 只有两条不重合的直径上的四个点才能组成一个矩形, 所 ...

  9. [转贴]VC编译器版本号_MSC_VER and _MSC_FULL_VER

    Visual Studio version and discrimination macros Abbreviation Product name [Visual Studio version] †1 ...

  10. ubuntu下搭建Discuz

      环境:我用桥接方式创建了一个ubuntu16的虚拟机,ip为192.168.0.220   1.安装mysql sudo apt-get install mysql-server mysql-cl ...