【发布时间】:2021-10-04 07:15:30
【问题描述】:
为了确保媒体查询确实有效并且问题不是我设置了错误的最大宽度,我将导航栏设置为在达到最大宽度时更改颜色和高度。我的主要目标是让搜索栏进一步向左移动,但这不起作用(背景颜色的变化是出于视觉目的)。为什么会这样?我正在尝试重新定位搜索栏,因为一旦屏幕变小它就会出现故障。
nav ul {
display: inline-flex;
list-style: none;
transform: translate(16%);
}
nav ul li {
margin-right: 50px;
}
.search {
border-radius: 40px;
background-color: rgb(255, 255, 255);
display: inline-flex;
height: 35px;
transform: translate(180px, -1px);
}
.search input {
position: relative;
left: 10px;
top: 0px;
outline: none;
width: 0px;
border: none;
background: transparent;
transition: 0.5s;
}
search:hover input {
width: 150px;
}
.btn {
height: 35px;
width: 35px;
border-radius: 35px;
background-color: lightseagreen;
}
.btn i {
position: Relative;
top: 9px;
left: 9px;
}
@media screen and (max-width: 1380px) {
nav {
background-color: greenyellow;
height: 40px;
}
.search {
background-color: indigo;
}
}
<nav>
<ul>
<li><a href=#>word1</a></li>
<li><a href=#>word2</a></li>
<li><a href=#>word3</a></li>
</ul>
<div class="search">
<input type="text" placeholder="search">
<div class=btn>
<i class="fas fa-search"></i>
</div>
</div>
</nav>
【问题讨论】:
-
请在minimal reproducable example 中添加更多详细信息,例如html,最多在stack snippet 中添加。见how to ask
-
请ask a good question 包括minimal reproducible example。在Stack snippet中提供所有必需的代码
-
顺便问一下:背景颜色在断点处改变了吗?
-
@biberman 它已被添加!背景颜色仅更改为 nav 而不是 .search
-
搜索也会发生变化,但您看不到它,因为输入的宽度为零。剩下的我稍后再看……
标签: css media-queries