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

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

How to adjust the sidebar size in React

问题

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

// App.css
.sidemenu {
  width: 1000px;
  border: 1px solid white;
}

// App.js
import logo from './logo.svg';
import './App.css';

function App() {
  return (
    <div className="App">
      <aside className="sidemenu">
        <h1>侧边栏</h1>
      </aside>
      <section>

      </section>
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
        <p>
          编辑 <code>src/App.js</code> 并保存以重新加载
        </p>
        <a
          className="App-link"
          href="https://reactjs.org"
          target="_blank"
          rel="noopener noreferrer"
        >
          学习React
        </a>
      </header>
    </div>
  );
}

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:

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

My App.js code is as follows:

import logo from &#39;./logo.svg&#39;;
import &#39;./App.css&#39;;

function App() {
  return (
    &lt;div className=&quot;App&quot;&gt;
     &lt;aside className=&quot;sidemenua&quot;&gt;
       &lt;h1&gt;Aside&lt;/h1&gt;
     &lt;/aside&gt;
     &lt;section&gt;

     &lt;/section&gt;
     &lt;header className=&quot;App-header&quot;&gt;
      &lt;img src={logo} className=&quot;App-logo&quot; alt=&quot;logo&quot; /&gt;
      &lt;p&gt;
        Edit &lt;code&gt;src/App.js&lt;/code&gt; and save to reload.
      &lt;/p&gt;
      &lt;a
        className=&quot;App-link&quot;
        href=&quot;https://reactjs.org&quot;
        target=&quot;_blank&quot;
        rel=&quot;noopener noreferrer&quot;
      &gt;
        Learn React
      &lt;/a&gt;
    &lt;/header&gt;
   &lt;/div&gt;
);
}
 export default App;

Expected layout

My layout

答案1

得分: 1

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

&lt;aside className=&quot;sidemenu&quot;&gt;
    &lt;h1&gt;Aside&lt;/h1&gt;
&lt;/aside&gt;
英文:

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

&lt;aside className=&quot;sidemenu&quot;&gt;
    &lt;h1&gt;Aside&lt;/h1&gt;
&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:

确定