css 为什么当屏幕变小时,导航栏的一部分会消失

bmp9r5qi  于 2023-04-08  发布在  其他
关注(0)|答案(2)|浏览(167)

我用React和CSS创建了一个导航栏,代码如下:

<header className="home-header">
      <div className="auth-buttons">
         <input type="button" className="auth-button sign-up-button" value="Sign Up" />
         <input type="button" className="auth-button login-button" value="Login" />
     </div>
     <div className="menus-container">
         My Site
         <span></span>
         <span></span>
         <span></span>
    </div>
</header>

.home-header {
    position: sticky;
    padding: 1.5rem;
    margin-top: 0;
    min-width: 100vh;
  
    background-color: #1441aa;
    border-bottom-right-radius: 30px;
    box-shadow: 0 3px 10px rgb(0 0 0 / 0.2);
  
    display: flex;
    flex-direction: row;
    justify-content: space-between;
  }

  .home-header .auth-buttons {
    display: flex;
    flex-direction: row;
    gap: 3px;
    /* margin-left: 10%; */
  }

  .home-header .auth-buttons .auth-button {
    padding: 0.5rem 1.5rem;
    border: none;
  }

  .home-header .auth-buttons .auth-button:hover {
    cursor: pointer;
  }

  .home-header .auth-buttons .sign-up-button {
     border-bottom-left-radius: 1rem;
  }

  .home-header .menus-container {
    /* margin-left: 60%; */
    color: #fff;
    font-size: 1.5rem;
    font-weight: 400;
  }

  .home-header .auth-buttons .login-button {
    border-top-right-radius: 1rem;
  }

但是当我把屏幕变小时,导航栏的右边部分就消失了,如下图所示:
全屏:

更小的屏幕:

我希望导航栏能够响应,并且随着屏幕变小而变小,而不是消失。你能帮我吗?

3vpjnl9f

3vpjnl9f1#

这是因为你设置了min-width: 100vh;,这是指窗口的高度。你需要将其更改为vw(视口宽度)或使用%

.home-header {
    position: sticky;
    padding: 1.5rem;
    margin-top: 0;
    min-width: 100%; // the difference is this value
  
    background-color: #1441aa;
    border-bottom-right-radius: 30px;
    box-shadow: 0 3px 10px rgb(0 0 0 / 0.2);
  
    display: flex;
    flex-direction: row;
    justify-content: space-between;
  }

  .home-header .auth-buttons {
    display: flex;
    flex-direction: row;
    gap: 3px;
    /* margin-left: 10%; */
  }

  .home-header .auth-buttons .auth-button {
    padding: 0.5rem 1.5rem;
    border: none;
  }

  .home-header .auth-buttons .auth-button:hover {
    cursor: pointer;
  }

  .home-header .auth-buttons .sign-up-button {
     border-bottom-left-radius: 1rem;
  }

  .home-header .menus-container {
    /* margin-left: 60%; */
    color: #fff;
    font-size: 1.5rem;
    font-weight: 400;
  }

  .home-header .auth-buttons .login-button {
    border-top-right-radius: 1rem;
  }
<header class="home-header">
      <div class="auth-buttons">
         <input type="button" class="auth-button sign-up-button" value="Sign Up" />
         <input type="button" class="auth-button login-button" value="Login" />
     </div>
     <div class="menus-container">
         My Site
         <span></span>
         <span></span>
         <span></span>
    </div>
</header>
rm5edbpk

rm5edbpk2#

.home-header的CSS中,min-width的大小是以vh为单位而不是vw,这意味着它将根据屏幕的高度而不是宽度进行缩放。
min-width: 100vh;更改为min-width: 100vw;
另外,由于填充的原因,页眉可能会从屏幕右侧被截断。添加规则box-sizing: border-box;,以便正确调整页眉的大小。

相关问题