检查此链接(演示2) https://codepen.io/912lab/pen/LsplC
html,
body {
font-family: 'Arial', sans-serif;
font-size: 16px;
}
/* border-box */
.search-container *,
.search-container *:after,
.search-container *:before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
}
/* search bar focus */
.search-container *:focus {
background: #fbfbfb;
color: #333333;
outline: 0;
}
/* search bar container */
.search-container {
display: table;
position: relative;
width: 51px;
}
/* search icon button */
.search-icon-btn {
background-color: aquamarine;
border: 1px solid aquamarine;
display: table-cell;
height: 50px;
position: relative;
text-align: center;
vertical-align: middle;
width: 50px;
z-index: 2;
}
/* search bar input container */
.search-input {
position: absolute;
left: 0;
z-index: 1;
}
/* search bar input */
.search-input input.search-bar {
border: 1px solid #cccccc;
height: 50px;
padding: 0px;
width: 50px;
}
.search-input input.search-bar:focus {
padding-left: 60px;
padding-right: 10px;
width: 200px;
}
/* transition effect */
.search-input input.search-bar,
.search-icon-btn {
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-ms-transition: all 0.5s;
-o-transition: all 0.5s;
transition: all 0.5s;
}
/* hover on search bar container */
.search-container:hover > .search-input input.search-bar {
padding-left: 60px;
padding-right: 10px;
width: 200px;
}
<h1>Expandable Search Form</h1>
<p>Pen by <a href="http://textfaces.wtf">Prinzadi</a></p>
<h3>Demo 1</h3>
<form>
<input type="search" placeholder="Search">
</form>
<h3>Demo 2</h3>
<form id="demo-2">
<input type="search" placeholder="Search">
</form>
是否可以将演示2上的搜索扩展到左侧而不是右侧?我更改了填充和宽度,但是它仍然向左扩展,而不是向右扩展。
再次,我尝试了几种不同的方法,但是我想我缺少了一些愚蠢的东西。感谢您的帮助。
谢谢
答案 0 :(得分:0)
使用CSS属性float: right
时,它会从右向左扩展。
代码如下:
body {
background: #fff;
color: #666;
font: 90%/180% Arial, Helvetica, sans-serif;
width: 800px;
max-width: 96%;
margin: 0 auto;
}
a {
color: #69C;
text-decoration: none;
}
a:hover {
color: #F60;
}
h1 {
font: 1.7em;
line-height: 110%;
color: #000;
}
p {
margin: 0 0 20px;
}
input {
outline: none;
}
input[type=search] {
-webkit-appearance: textfield;
-webkit-box-sizing: content-box;
font-family: inherit;
font-size: 100%;
}
input::-webkit-search-decoration,
input::-webkit-search-cancel-button {
display: none;
}
input[type=search] {
background: #ededed url(https://static.tumblr.com/ftv85bp/MIXmud4tx/search-icon.png) no-repeat 9px center;
border: solid 1px #ccc;
padding: 9px 10px 9px 32px;
width: 55px;
-webkit-border-radius: 10em;
-moz-border-radius: 10em;
border-radius: 10em;
-webkit-transition: all .5s;
-moz-transition: all .5s;
transition: all .5s;
float: right;
margin-right: 701px;
}
input[type=search]:focus {
width: 120px;
background-color: #fff;
border-color: #66CC75;
float: right;
-webkit-box-shadow: 0 0 5px rgba(109,207,246,.5);
-moz-box-shadow: 0 0 5px rgba(109,207,246,.5);
box-shadow: 0 0 5px rgba(109,207,246,.5);
}
input:-moz-placeholder {
color: #999;
}
input::-webkit-input-placeholder {
color: #999;
}
/* Demo 2 */
#demo-2 input[type=search] {
width: 15px;
padding-left: 10px;
color: transparent;
cursor: pointer;
}
#demo-2 input[type=search]:hover {
background-color: #fff;
}
#demo-2 input[type=search]:focus {
width: 130px;
padding-left: 32px;
color: #000;
background-color: #fff;
cursor: auto;
}
#demo-2 input:-moz-placeholder {
color: transparent;
}
#demo-2 input::-webkit-input-placeholder {
color: transparent;
}
<h1>Expandable Search Form</h1>
<p>Pen by <a href="http://textfaces.wtf">Prinzadi</a></p>
<h3>Demo 1</h3>
<div class="container">
<form>
<input type="search" placeholder="Search">
</form>
</div>
由于某种原因,输入在“堆栈代码段”中不起作用,因此只需将其复制到CodePen或您选择的任何其他平台中即可。
这不是您想要的位置,因此我在CSS中设置了一个margin-right
属性,将其更改回原来的状态。
我也没有在第二个演示中修复它,因为我希望您通过查看我所做的更改然后自己实施来弄清楚如何自己进行更改。这样一来,您将了解将来如何复制此解决方案并总体上增加对HTML / CSS的了解。