React Bootstrap和MDB Bootstrap在Hilla/Vaadin内部不起作用。

huangapple go评论97阅读模式
英文:

React boostrap and MDB boostrap doesn't work inside Hilla/Vaadin

问题

除了调整类别特异性以外,还有其他方法可以覆盖此样式吗?内联样式或类别特异性非常耗时,我希望有更快的选择。

谢谢你提前给我提供的任何帮助。


你可以尝试使用全局样式覆盖这些样式,而不必依赖类别特异性或内联样式。为此,你可以在你的React应用程序中创建一个全局CSS文件,并在其中定义样式规则,以覆盖默认样式。

首先,在你的项目中创建一个全局CSS文件,例如"global.css",并确保在应用程序中引入它。

然后,你可以在这个全局CSS文件中定义你希望覆盖的样式规则。例如,如果你想更改form元素的样式,可以这样做:

  1. /* global.css */
  2. form {
  3. /* 你的自定义样式规则 */
  4. background-color: #fff; /* 以你希望的背景颜色为例 */
  5. /* 添加其他自定义样式属性 */
  6. }

这将会覆盖默认样式中的form元素样式。确保在全局CSS中使用足够的特异性以确保你的规则优先于默认样式。

最后,确保在React组件中引入这个全局CSS文件,以便应用你的自定义样式。

使用全局CSS覆盖样式是一种更快的方式,不需要依赖类别特异性或内联样式。希望这可以帮助你解决问题!

英文:

pretty much the question.
i have a hilla/vaadin spring boot application running and i want to experiment implementing react boostrap inside my application.
i installed both react boostrap and mdb boostrap using npm in my root folder
the thing is when i look at my page in my localhost the boostrap style is not applied.
this is my page:

  1. import { useState } from 'react';
  2. import {
  3. MDBValidation,
  4. MDBValidationItem,
  5. MDBInput,
  6. MDBInputGroup,
  7. MDBBtn,
  8. MDBCheckbox
  9. } from 'mdb-react-ui-kit';
  10. export default function AboutView() {
  11. const [formValue, setFormValue] = useState({
  12. fname: 'Mark',
  13. lname: 'Otto',
  14. email: '',
  15. city: '',
  16. state: '',
  17. zip: '',
  18. });
  19. const onChange = (e: any) => {
  20. setFormValue({ ...formValue, [e.target.name]: e.target.value });
  21. };
  22. return (
  23. <MDBValidation className='row g-3'>
  24. <MDBValidationItem className='col-md-4'>
  25. <MDBInput
  26. value={formValue.fname}
  27. name='fname'
  28. onChange={onChange}
  29. id='validationCustom01'
  30. required
  31. label='First name'
  32. />
  33. </MDBValidationItem>
  34. <MDBValidationItem className='col-md-4'>
  35. <MDBInput
  36. value={formValue.lname}
  37. name='lname'
  38. onChange={onChange}
  39. id='validationCustom02'
  40. required
  41. label='Last name'
  42. />
  43. </MDBValidationItem>
  44. <MDBValidationItem feedback='Please choose a username.' invalid className='col-md-4'>
  45. <MDBInputGroup textBefore='@'>
  46. <input
  47. type='text'
  48. className='form-control'
  49. id='validationCustomUsername'
  50. placeholder='Username'
  51. required
  52. />
  53. </MDBInputGroup>
  54. </MDBValidationItem>
  55. <MDBValidationItem className='col-md-6' feedback='Please provide a valid city.' invalid>
  56. <MDBInput
  57. value={formValue.city}
  58. name='city'
  59. onChange={onChange}
  60. id='validationCustom03'
  61. required
  62. label='City'
  63. />
  64. </MDBValidationItem>
  65. <MDBValidationItem className='col-md-6' feedback='Please provide a valid zip.' invalid>
  66. <MDBInput
  67. value={formValue.zip}
  68. name='zip'
  69. onChange={onChange}
  70. id='validationCustom05'
  71. required
  72. label='Zip'
  73. />
  74. </MDBValidationItem>
  75. <MDBValidationItem className='col-12' feedback='You must agree before submitting.' invalid>
  76. <MDBCheckbox label='Agree to terms and conditions' id='invalidCheck' required />
  77. </MDBValidationItem>
  78. <div className='col-12'>
  79. <MDBBtn type='submit'>Submit form</MDBBtn>
  80. <MDBBtn type='reset'>Reset form</MDBBtn>
  81. </div>
  82. </MDBValidation>
  83. );
  84. }

after inspecting the page i found that the style applied is exclusevely lumo not mine:

  1. user agent stylesheet
  2. form {
  3. display: block;
  4. margin-top: 0em;
  5. }
  6. style attribute {
  7. --_vaadin-app-layout-navbar-offset-size: 57px;
  8. --_vaadin-app-layout-navbar-offset-size-bottom: 0px;
  9. --_vaadin-app-layout-drawer-offset-size: 320px;
  10. }
  11. <style>
  12. :host([overlay]) {
  13. --vaadin-app-layout-drawer-offset-left: 0;
  14. --vaadin-app-layout-navbar-offset-left: 0;
  15. }
  16. @media (max-width: 800px), (max-height: 600px)
  17. <style>
  18. :host {
  19. --vaadin-app-layout-drawer-overlay: true;
  20. }
  21. <style>
  22. :host {
  23. display: block;
  24. box-sizing: border-box;
  25. height: 100%;
  26. --vaadin-app-layout-transition: 200ms;
  27. transition: padding var(--vaadin-app-layout-transition);
  28. --vaadin-app-layout-touch-optimized: false;
  29. --vaadin-app-layout-navbar-offset-top: var(--_vaadin-app-layout-navbar-offset-size);
  30. --vaadin-app-layout-navbar-offset-bottom: var(--_vaadin-app-layout-navbar-offset-size-bottom);
  31. padding-block: var(--vaadin-app-layout-navbar-offset-top) var(--vaadin-app-layout-navbar-offset-bottom);
  32. padding-inline-start: var(--vaadin-app-layout-navbar-offset-left);
  33. }
  34. <style>
  35. body, html {
  36. font-family: var(--lumo-font-family);
  37. font-size: var(--lumo-font-size-m);
  38. line-height: var(--lumo-line-height-m);
  39. -webkit-text-size-adjust: 100%;
  40. -webkit-font-smoothing: antialiased;
  41. -moz-osx-font-smoothing: grayscale;
  42. }

is there any way to overrule this? other than playing with class specificity?
inline style or class specificity are very time consuming and i would like a faster option

thank you in advance for any help you can give me.

答案1

得分: 1

尝试使用以下内容在你的index.html文件中引用Bootstrap连接:

  1. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css">
  2. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
英文:

Try the bootstrap connection using the

  1. &lt;link rel=&quot; stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css&quot;&gt;

and

  1. &lt;script src=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js&quot;&gt;
  2. &lt;/script&gt;

in your index.html file

huangapple
  • 本文由 发表于 2023年6月15日 16:07:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76480377.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定