【问题标题】:Aligning Search bar with other elements in the nav将搜索栏与导航中的其他元素对齐
【发布时间】:2018-02-13 10:36:20
【问题描述】:

我之前问过一个关于在导航栏最右侧移动搜索栏的问题,按照我确实成功将其向右移动的答案,但是现在搜索栏与其他元素不对齐(以前是)。哪个 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>

【问题讨论】:

    标签: html css frontend searchbar web-frontend


    【解决方案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 并删除最后一个孩子的 margin-bottom。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-10
      • 2018-07-30
      • 1970-01-01
      • 2017-05-12
      • 2016-08-08
      • 1970-01-01
      • 2015-03-16
      • 1970-01-01
      相关资源
      最近更新 更多