6.jsx_样式绑定.html 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <script src="./babel.min.js"></script>
  8. <script src="./react.development.js"></script>
  9. <script src="./react-dom.development.js"></script>
  10. <style>
  11. .head {
  12. color: orange;
  13. }
  14. .aa {
  15. color: red;
  16. }
  17. .bb {
  18. font-style: italic;
  19. }
  20. .cc {
  21. text-decoration: underline;
  22. }
  23. .dd {
  24. background: #ff0;
  25. }
  26. .ee {
  27. background: #00f;
  28. }
  29. </style>
  30. <!-- <link rel="stylesheet" href="./css/b.css" precedence="high">
  31. <link rel="stylesheet" href="./css/a.css" precedence="low"> -->
  32. </head>
  33. <body>
  34. <div id="root"></div>
  35. <script type="text/babel">
  36. const news = 'aa';
  37. const isActive = false;
  38. const other = ['aa', 'cc', isActive ? 'dd' : 'ee']
  39. const element = (
  40. <div>
  41. {/* 单个类名 */}
  42. <h1 className='head'>Class样式绑定</h1>
  43. {/* 多个类名:字符串 */}
  44. <h3 className={'aa bb'}>哈哈哈</h3>
  45. {/* 多个类名:模版字符串 */}
  46. <div className={`${news} ${isActive ? 'bb' : 'cc'}`}>大家好</div>
  47. {/* 多个类名:数组 + join() */}
  48. <div className={other.join(' ')}>endeing</div>
  49. <div className='end'>最后</div>
  50. </div>
  51. )
  52. const container = document.getElementById("root");
  53. const root = ReactDOM.createRoot(container)
  54. root.render(element);
  55. </script>
  56. </body>
  57. </html>