本文主要包含CSS3,Transition等相关知识,dopppler 希望在学习及工作中可以帮助到您
1.会伸缩的搜索表单
常在 sf.gg 混的人都知道,它的顶部导航栏是这样的:
当输入框获得焦点就会变成这样的:
利用 CSS3 的 Transition 属性,我们可以简单做出一个类似的搜索表单出来:
HTML 标记:
- <header>
- <form action="#" method="post" class="searchForm">
- <label for="search">search</label>
- <input type="search" id="search" name="search" placeholder="search">
- </form>
- </header>
CSS 样式:
- *{
- margin: 0;
- padding: 0;
- }
- header{
- font-family: helvetica,arial,sans-serif;
- display: block;
- overflow: hidden;
- width:500px;
- margin: 15px;
- border-radius: 3px;
- background-color: #ddd;
- }
- form.searchForm{
- /*包含label和input的容器*/
- width: 200px;
- margin: 5px;
- padding: 5px;
- }
- form.searchForm input{
- width: 90px;
- padding: 2px 0 3px 5px;
- outline: none;
- font-size: 1.2em;
- border-color: #eee #ccc #ccc #eee;
- border-radius: 10px;
- /*针对webkit内核的浏览器的厂商前缀*/
- -webkit-transition:0.5s width;
- }
- form.searchForm input:focus{
- width: 400px; /*如果失去焦点,则缩回原来长度*/
- }
- form.searchForm label{
- display