如何调整 React 中侧边栏的大小

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

How to adjust the sidebar size in React

问题

看起来你在React中遇到了一些问题。以下是你提供的代码的中文翻译:

  1. // App.css
  2. .sidemenu {
  3. width: 1000px;
  4. border: 1px solid white;
  5. }
  6. // App.js
  7. import logo from './logo.svg';
  8. import './App.css';
  9. function App() {
  10. return (
  11. <div className="App">
  12. <aside className="sidemenu">
  13. <h1>侧边栏</h1>
  14. </aside>
  15. <section>
  16. </section>
  17. <header className="App-header">
  18. <img src={logo} className="App-logo" alt="logo" />
  19. <p>
  20. 编辑 <code>src/App.js</code> 并保存以重新加载
  21. </p>
  22. <a
  23. className="App-link"
  24. href="https://reactjs.org"
  25. target="_blank"
  26. rel="noopener noreferrer"
  27. >
  28. 学习React
  29. </a>
  30. </header>
  31. </div>
  32. );
  33. }
  34. export default App;

希望这能帮助你解决问题。

英文:

I am new to react, and I am working on my first project, following https://www.youtube.com/watch?v=qwM23_kF4v4.

At the very beginning, I followed all the steps and tries to set a sidebar on the left with "240px", the expected is as left, but what I made is as right.

The code is below. I only add the sidemenu part.

I have rechecked the code in the video many times, but it still shows as below. Furthermore, I expected the sidebar to be 50% of the screen, as shown in the video.

I have changed the sidemenu width as "100%", "40vmin", but nothing works.
What I have tried is as follows in App.css:

  1. .sidemenu {
  2. width: 1000px;
  3. border:1px solid white;
  4. }

My App.js code is as follows:

  1. import logo from &#39;./logo.svg&#39;;
  2. import &#39;./App.css&#39;;
  3. function App() {
  4. return (
  5. &lt;div className=&quot;App&quot;&gt;
  6. &lt;aside className=&quot;sidemenua&quot;&gt;
  7. &lt;h1&gt;Aside&lt;/h1&gt;
  8. &lt;/aside&gt;
  9. &lt;section&gt;
  10. &lt;/section&gt;
  11. &lt;header className=&quot;App-header&quot;&gt;
  12. &lt;img src={logo} className=&quot;App-logo&quot; alt=&quot;logo&quot; /&gt;
  13. &lt;p&gt;
  14. Edit &lt;code&gt;src/App.js&lt;/code&gt; and save to reload.
  15. &lt;/p&gt;
  16. &lt;a
  17. className=&quot;App-link&quot;
  18. href=&quot;https://reactjs.org&quot;
  19. target=&quot;_blank&quot;
  20. rel=&quot;noopener noreferrer&quot;
  21. &gt;
  22. Learn React
  23. &lt;/a&gt;
  24. &lt;/header&gt;
  25. &lt;/div&gt;
  26. );
  27. }
  28. export default App;

Expected layout

My layout

答案1

得分: 1

请检查你的className是否与 CSS 选择器名称不同,应该是sidemenu

  1. &lt;aside className=&quot;sidemenu&quot;&gt;
  2. &lt;h1&gt;Aside&lt;/h1&gt;
  3. &lt;/aside&gt;
英文:

please check your className is differ from css selector name it should be
sidemenu.

  1. &lt;aside className=&quot;sidemenu&quot;&gt;
  2. &lt;h1&gt;Aside&lt;/h1&gt;
  3. &lt;/aside&gt;

huangapple
  • 本文由 发表于 2023年2月6日 03:17:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75354869.html
匿名

发表评论

匿名网友

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

确定