我之前问了一个关于在导航栏最右侧移动搜索栏的问题,按照我成功将其向右移动的答案,但是现在搜索栏与其他元素不一致(以前它是)。哪个CSS属性(如果有的话)阻止它发生以及可能是什么解决方案?
代码:
body
{
margin: 0;
background: #222;
font-weight: 300;
background-image: url('logo.jpeg');
}
.container
{
width: 80%;
margin: 0 auto;
}
header
{
background: #f3e5ab;
position: relative;
}
header::after
{
content: '';
display: table;
clear: both;
}
nav
{
float: left;
}
nav ul
{
margin: 0;
padding: 0;
list-style: none;
}
nav li
{
display: inline-block;
margin-left: 70px;
padding-top: 30px;
position: relative;
}
nav ul li a
{
color: #444;
text-decoration: none;
text-transform: uppercase;
font-size: 14px;
}
nav a:hover
{
}
nav a::before
{
content: '';
display: block;
height: 5px;
width: 0%;
background-color: #444;
transition: all ease-in-out 500ms;
}
nav a:hover::before
{
width: 100%;
}
form .form
{
float: right;
}
.search-bar
{
float: right;
}
ul li:last-child
{
position: absolute;
right: 0;
top: 0;
margin: 15px;
padding: 0;
}

<header>
<div class="container">
<nav>
<ul>
<li> <a href="#"> Home </a></li>
<li> <a href="#"> About </a></li>
<li> <a href="#"> Services </a></li>
<li> <a href="#"> Products </a></li>
<li> <a href="#"> Contact Us </a></li>
<li> <form class="form"> <input type="text" name="Search" placeholder="Search"> </form> </li>
</ul>
</nav>
</div>
</header>
&#13;
答案 0 :(得分:1)
我不能说我在同一页面上就你选择的总体布局和方法而言,但这里有一个快速修复(如果我理解你的问题)
https://codepen.io/magom001/pen/mXwovO?editors=1100
body
{
margin: 0;
background: #222;
font-weight: 300;
background-image: url('logo.jpeg');
}
.container
{
width: 80%;
margin: 0 auto;
}
.container::after {
content: '';
displayt: table;
clear: both;
}
header
{
background: #f3e5ab;
position: relative;
}
header::after
{
content: '';
display: table;
clear: both;
}
nav
{
float: left;
}
nav ul
{
margin: 0;
padding: 0;
list-style: none;
}
nav li
{
display: inline-block;
margin-left: 70px;
padding-top: 30px;
position: relative;
}
nav ul li a
{
color: #444;
text-decoration: none;
text-transform: uppercase;
font-size: 14px;
}
nav a:hover
{
}
nav a::before
{
content: '';
display: block;
height: 5px;
width: 0%;
background-color: #444;
transition: all ease-in-out 500ms;
}
nav a:hover::before
{
width: 100%;
}
form .form
{
float: right;
}
.search-bar
{
float: right;
}
ul li:last-child
{
position: absolute;
right: 0;
bottom: 0;
margin: 15px;
margin-bottom: 0px;
padding: 0;
}
只需更改top:0到bottom:0并删除last-child上的margin-bottom。