英文:
Why does a part of the navigation bar disappear when the screen gets smaller
问题
I created a nav bar in React and CSS with the following code:
<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>
and
.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;
}
.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 {
color: #fff;
font-size: 1.5rem;
font-weight: 400;
}
.home-header .auth-buttons .login-button {
border-top-right-radius: 1rem;
}
But when I make the screen smaller, the right part of the navbar disappears. I want the nav bar to be responsive and get smaller as the screen gets smaller, not disappear. Could you help me?
英文:
I created a nav bar in React and CSS with the following code:
<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>
and
.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;
}
But when I make the screen smaller, the right part of the navbar disappears, as shown below:
Full Screen:
Smaller Screen:
I want the nav bar to be responsive and get smaller as the screen gets smaller, not disappear. Could you help me?
答案1
得分: 1
以下是翻译好的内容:
因为您设置了min-width: 100vh;
,它指的是窗口的高度。您需要将其更改为vw
(视口宽度)或使用百分比(%)。
.home-header {
position: sticky;
padding: 1.5rem;
margin-top: 0;
min-width: 100%; // 不同的是这个值
background-color: #1441aa;
border-bottom-right-radius: 30px;
box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
display: flex;
flex-direction: row;
justify-content: space-between;
}
<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>
英文:
It's because u set min-width: 100vh;
which referts to the window height. You need to change that to vw
(viewport width) or use %
.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.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;
}
<!-- language: lang-html -->
<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>
<!-- end snippet -->
答案2
得分: 1
在.home-header
的CSS中,min-width
是使用vh
单位而不是vw
单位进行大小调整,这意味着它将根据屏幕的高度而不是宽度进行缩放。
将min-width: 100vh;
更改为min-width: 100vw;
。
此外,由于内边距的原因,您的页眉可能会在屏幕右侧被裁切。添加规则 box-sizing: border-box;
以确保它被正确调整大小。
英文:
In the CSS for .home-header
, min-width
is sized with the vh
unit rather than vw
, meaning it will scale according to the height of the screen rather than the width.
Change min-width: 100vh;
to min-width: 100vw;
.
Additionally, your header may get cut off the right side of screen due to its padding. Add the rule box-sizing: border-box;
so that it will be sized correctly.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论