我的導航欄有問題,一旦我將瀏覽器選項卡變小,文本將保持相同大小,但徽標會變得越來越小并消失。我怎樣才能讓它變得更小?如果需要更多資訊,我會提供給他們。以下是我的問題的一些示例。 例如,100% 寬度頁面vs頁面變小以適應較小的螢屏
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
/* custom scroll bar */
::-webkit-scrollbar {
width: 10px;
}
::-webkit-scrollbar-track {
background: #f1f1f1;
}
::-webkit-scrollbar-thumb {
background: #888;
}
::selection {
background: rgb(0, 123, 255, 0.3);
}
.content {
max-width: 1250px;
margin: auto;
padding: 0 30px;
}
/* Nav start*/
.navbar {
position: fixed;
width: 100%;
z-index: 2;
padding: 25px 0;
transition: all 0.3s ease;
background-color: black;
}
.navbar.sticky {
background: black;
padding: 10px 0;
box-shadow: 0px 3px 5px 0px rgba(0, 0, 0, 0.1);
}
.navbar .content {
display: flex;
align-items: center;
justify-content: space-between;
}
.navbar .logo a {
color: #fff;
font-size: 30px;
font-weight: 600;
text-decoration: none;
}
.navbar .menu-list {
display: inline-flex;
}
.menu-list li {
list-style: none;
}
.menu-list li a {
color: #fff;
font-size: 18px;
font-weight: 500;
margin-left: 20px;
text-decoration: none;
transition: all 0.3s ease;
}
.menu-list li a:hover {
color: #007bff;
}
.banner {
height: 100vh;
background-position: center;
background-attachment: fixed;
}
.about {
padding: 30px 0;
}
.about .title {
font-size: 38px;
font-weight: 700;
}
.about p {
padding-top: 20px;
text-align: justify;
}
.icon {
color: #fff;
font-size: 20px;
cursor: pointer;
display: none;
}
.menu-list .cancel-btn {
position: absolute;
right: 30px;
top: 20px;
}
@media (max-width: 1230px) {
.content {
padding: 0 60px;
}
}
@media (max-width: 1100px) {
.content {
padding: 0 40px;
}
}
@media (max-width: 900px) {
.content {
padding: 0 30px;
}
}
@media (max-width: 868px) {
body.disabled {
overflow: hidden;
}
.icon {
display: block;
}
.icon.hide {
display: none;
}
.navbar .menu-list {
position: fixed;
height: 100vh;
width: 100%;
max-width: 400px;
left: -100%;
top: 0px;
display: block;
padding: 40px 0;
text-align: center;
background: #222;
transition: all 0.3s ease;
}
.navbar.show .menu-list {
left: 0%;
}
.navbar .menu-list li {
margin-top: 45px;
}
.navbar .menu-list li a {
font-size: 23px;
margin-left: -100%;
transition: 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.navbar.show .menu-list li a {
margin-left: 0px;
}
}
@media (max-width: 380px) {
.navbar .logo a {
font-size: 27px;
}
}
.cta {
padding: 9px 25px;
background-color: rgba(0, 136, 169, 1);
border: none;
border-radius: 50px;
cursor: pointer;
transition: background-color 0.3s ease 0s;
}
.cta:hover {
background-color: rgba(0, 136, 169, 0.8);
}
/* Nav end*/
<nav class="navbar">
<div class="content">
<div class="logo">
<a href="/index.html"><img src="images/logo-villa-dor.jpg" width="100%"></a>
</div>
<ul class="menu-list">
<div class="icon cancel-btn">
<i class="fas fa-times"></i>
</div>
<li><a href="/fireplaces.html">Fireplaces</a></li>
<li><a href="/floorings.html">Floorings</a></li>
<li><a href="/iron_works.html">IronWorks</a></li>
<li><a href="/ornaments.html">Ornaments</a></li>
<li><a href="/Woodwork.html">Woodwork</a></li>
<li><a href="/Radiators.html">Radiators</a></li>
<li><a href="/luminairy.html">Luminary</a></li>
<li><a href="/miscellaneous.html">Miscellaneous</a></li>
</ul>
<div class="icon menu-btn">
<i class="fas fa-bars"></i>
</div>
</div>
</nav>
uj5u.com熱心網友回復:
我認為您使用@media 是錯誤的。
@media (max-width: 868px)
表示這些樣式將在最大寬度為 868px 時應用。所以對于小螢屏,你需要減少那里的字體大小。
@media (max-width: 868px) {
.navbar .menu-list li a{
font-size: 16px; // for example
margin-left: -100%;
transition: 0.6s cubic-bezier(0.68, -0.55, 0.265,
1.55);
}
}
uj5u.com熱心網友回復:
我看到你的風格中的一些問題已被證明對你的設計有問題。為了演示該media-queries行為,我洗掉了您的所有內容media queries,只制作了一個指向您<ul>和您的logo 的內容,這似乎是本示例中的焦點。
請參閱我在/* Media Start&之間所做的 CSS 更改/* Media End */。另外,我的建議,如果你是彎曲的導航欄,是使用display: flex;替代inline-flex。然后您可以添加justify-content: space-between;以正確對齊導航組件。接下來,這只是出于偏好,但我不建議將您li's與margin-left您間隔開,因為那樣您會在“壁爐”上獲得左邊距,<li>這只是不必要的邊距。我用gap: 10px;作為替代。
請同時查看徽標的更改。有了這個正確的結構media-queries,我相信你會更容易操作。由于無法看到您的影像或其大小,因此很難為您提供精確的height & width因此25px根據需要調整周圍。最后,設定font-sizes徽標或影像將沒有用,除非在包含影像或徽標的父 div 中存在文本元素。
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
/* custom scroll bar */
::-webkit-scrollbar {
width: 10px;
}
::-webkit-scrollbar-track {
background: #f1f1f1;
}
::-webkit-scrollbar-thumb {
background: #888;
}
::selection{
background: rgb(0,123,255,0.3);
}
.content{
max-width: 1250px;
margin: auto;
padding: 0 30px;
}
/* Nav start*/
.navbar{
position: fixed;
width: 100%;
z-index: 2;
padding: 25px 0;
transition: all 0.3s ease;
background-color: black;
}
.navbar.sticky{
background: black;
padding: 10px 0;
box-shadow: 0px 3px 5px 0px rgba(0,0,0,0.1);
}
.navbar .content{
display: flex;
align-items: center;
justify-content: space-between;
}
.navbar .logo a{
color: #fff;
font-size: 30px;
font-weight: 600;
text-decoration: none;
}
.navbar .menu-list{
display: flex;
justify-content: space-between;
gap: 10px;
}
.menu-list li{
list-style: none;
}
.menu-list li a{
color: #fff;
font-size: 18px;
font-weight: 500;
text-decoration: none;
transition: all 0.3s ease;
}
.menu-list li a:hover{
color: #007bff;
}
.banner{
height: 100vh;
background-position: center;
background-attachment: fixed;
}
.about{
padding: 30px 0;
}
.about .title{
font-size: 38px;
font-weight: 700;
}
.about p{
padding-top: 20px;
text-align: justify;
}
.icon{
color: #fff;
font-size: 20px;
cursor: pointer;
display: none;
}
.menu-list .cancel-btn{
position: absolute;
right: 30px;
top: 20px;
}
.cta {
padding: 9px 25px;
background-color: rgba(0, 136, 169, 1);
border: none;
border-radius: 50px;
cursor: pointer;
transition: background-color 0.3s ease 0s;
}
.cta:hover {
background-color: rgba(0, 136, 169, 0.8);
}
/* Nav end*/
/* Media Start */
@media only screen and (max-width: 800px) {
ul.menu-list li a {
font-size: 10px;
}
.logo {
width: 25px;
height: 25px;
}
}
/* Media End */
<nav class="navbar">
<div class="content">
<div class="logo">
<a href="/index.html" ><img src="images/logo-villa-dor.jpg" width="100%"></a>
</div>
<ul class="menu-list">
<div class="icon cancel-btn">
<i class="fas fa-times"></i>
</div>
<li><a href="/fireplaces.html">Fireplaces</a></li>
<li><a href="/floorings.html">Floorings</a></li>
<li><a href="/iron_works.html">IronWorks</a></li>
<li><a href="/ornaments.html">Ornaments</a></li>
<li><a href="/Woodwork.html">Woodwork</a></li>
<li><a href="/Radiators.html">Radiators</a></li>
<li><a href="/luminairy.html">Luminary</a></li>
<li><a href="/miscellaneous.html">Miscellaneous</a></li>
</ul>
<div class="icon menu-btn">
<i class="fas fa-bars"></i>
</div>
</div>
</nav>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/376464.html
