1

在此处输入图像描述

现场小提琴:

http://jsfiddle.net/jMAzr/1/

Apple.com 上的工作示例:http: //www.apple.com/

<html>
<head>
<style>
body {
 background:#000000;   
}
li {
    list-style:none;
    display: list-item;
}
ul.menu li {
    float:left;
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
    text-decoration: none;
    font-weight: 400;
}
ul.menu li a {
    text-decoration:none;
}
.header-tab-title {
    display: block;
    position: relative;
    height: 46px;
    line-height: 46px;
    cursor: pointer;
    font-size: 16px;
    color: #fff;
    text-align: center;
}
.search-field {
    width: 70px;
    border-radius:10px;
    transition: width 0.5s ease-in-out,margin-left 0.5s ease-in-out;
    -webkit-transition: width 0.5s ease-in-out,margin-left 0.5s ease-in-out;
    -moz-transition: width 0.5s ease-in-out,margin-left 0.5s ease-in-out;
    -o-transition: width 0.5s ease-in-out,margin-left 0.5s ease-in-out;
    animation-direction:reverse;
    -webkit-animation-direction:reverse; /* Safari and Chrome */
    border: 1px solid #353535;
    height:18px;
    padding: 0px 23px 4px;
    color:#FFF;
}
.search-field:focus {
    color:#000;
    width: 140px;
    margin-left:-70px; 
    height:20px;
}
</style>
</head>
<body>
<ul class="menu">
<li><span class="header-tab-title" style="width:124px;">Produtos</span></li>
<li><span class="header-tab-title" style="width:151px;">Sites Prontos</span></li>
<li><span class="header-tab-title"style="width:192px;" >Anuncie no Google</span></li>
<li><span class="header-tab-title" style="width:230px;">Facebook Para Negócios</span></li>
<li><span class="header-tab-title" style="width:152px;">Hospedagem</span></li>
<li><span class="header-tab-title" style="width:110px;"><input class="search-field" type="search"></span></li>
</ul>
</body>
</html>
4

2 回答 2

3

您正在寻找的行为需要一个表格布局来随着一个“单元格”的增长而改变其他“单元格”的宽度。我用这种布局创建了一个简化的小提琴:

http://jsfiddle.net/Hp3JU/

我删除了几个元素来简化示例,但解决方案的本质是有一个 external display: table,然后是display:table-row每个“单元格” display:table-cell。给“表格”一个固定的宽度,并删除:hover伪类上的负边距,以防止最后一个单元格与其相邻单元格重叠。您还需要删除硬编码的固定宽度,以便您的单元格可以根据需要折叠以腾出空间。

<div class="table">
    <ul class="menu">
      <li>Produtos</li>
      <li>Sites Prontos</li>
      <li>Anuncie no Google</li>
      <li>Facebook Para Negócios</li>
      <li>Hospedagem</li>
      <li><input class="search-field" type="search" /></li>
    </ul>
</div>

CSS(仅相关部分):

.table {
    display: table;
    width: 100%;
}
ul.menu {
    display: table-row;
}
ul.menu > li {
    display: table-cell;
}
.search-field {
    width: 70px;
    border-radius:10px;
    transition: width 0.5s ease-in-out,margin-left 0.5s ease-in-out;
    -webkit-transition: width 0.5s ease-in-out,margin-left 0.5s ease-in-out;
    -moz-transition: width 0.5s ease-in-out,margin-left 0.5s ease-in-out;
    -o-transition: width 0.5s ease-in-out,margin-left 0.5s ease-in-out;
    animation-direction:reverse;
    -webkit-animation-direction:reverse; /* Safari and Chrome */
    border: 1px solid #353535;
    height:18px;
    padding: 0px 23px 4px;
    color:#FFF;
}
.search-field:focus {
    color:#000;
    width: 140px;
    height:20px;
}
于 2013-10-29T03:18:13.237 回答
1

Apple 通过在用户es 搜索字段nav时向元素添加一个类来做到这一点。focus

默认状态: 默认状态

活动状态:

活动状态

因此,要模仿相同的功能,您将需要 JavaScript 向ul.menu元素添加一个类。这个类将改变菜单的宽度。使用 CSS 动画来控制滑动效果。

于 2013-10-29T02:48:44.027 回答