Question

enter image description here

Live fiddle:

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

Working example at 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>
Was it helpful?

Solution

The behaviour you are looking for requires a table layout to change the width of the other "cells" as one grows. I have created a simplified fiddle with this layout:

http://jsfiddle.net/Hp3JU/

I've removed a couple of elements to simplify the example but the essence of the solution is to have an outer display: table, then a display:table-row then each "cell" is display:table-cell. Give the "table" a fixed width and remove the negative margin on the :hover psuedo-class to prevent the last cell overlapping its neighbor. You'll also need to remove your hardcoded fixed widths so your cells can collapse as required to make room.

<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 (Relevant parts only):

.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;
}

OTHER TIPS

Apple does it by adding a class to the nav element when the user focuses the search field.

Default State: default state

Active State:

active state

Thus, to mimic the same functionality you're going to need JavaScript to add a class to the ul.menu element. This class will change the width of the menu. Use CSS animations to control the sliding effect.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top