我有一个CSS可扩展的搜索字段,但我想要的是搜索项目覆盖前面两个图标,而不是将它们推到左边。我虽然可以通过将更高的z-index值应用于搜索表单并将更低的值应用于图标来实现此目的,但唉,我遗漏了一些东西。
这是一个链接,看看我在尝试什么。 TIA提供任何帮助!
https://codepen.io/anon/pen/Qprjjw#anon-login
这是HTML
public static void Main(string[] args)
{
//Your code goes here
Console.WriteLine("Hello, world!");
System.Globalization.CultureInfo ci = new CultureInfo("es-ES");
Console.WriteLine(true.ToString(ci));
}
// Hello, world!
// True
这是CSS
<h3>Search Demo</h3>
<div class="right">
<img src="http://static.tumblr.com/ftv85bp/MIXmud4tx/search-icon.png" alt="" width="" height="" border="" align="" />
<img src="http://static.tumblr.com/ftv85bp/MIXmud4tx/search-icon.png" alt="" width="" height="" border="" align="" />
<form id="search">
<input type="search" placeholder="Search">
</form>
</div>
答案 0 :(得分:0)
您可以使用position: absolute;
相对于等级right
的div来定位图像。
您需要在图像上设置z-index of
-1以使表单覆盖它们。
body {
background: #fff;
color: #666;
font: 90%/180% Arial, Helvetica, sans-serif;
width: 800px;
max-width: 96%;
margin: 0 auto;
}
.right {
float: right
}
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] {
outline: none;
color: #4a83c0;
-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(http://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;
}
input[type=search]:focus {
width: 130px;
background-color: #fff;
border-color: #66CC75;
-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: #4a83c0;
}
input::-webkit-input-placeholder {
color: #4a83c0;
}
/* Demo 2 */
#search {
display: inline-block;
}
/* new css */
.right {
position: relative;
}
.right img {
position: absolute;
top: 8px;
z-index: -1;
}
/* change these values to move the images to where you need */
.right img:nth-of-type(1) {
right: 40px;
}
.right img:nth-of-type(2) {
right: 60px;
}
#search input[type=search] {
width: 15px;
padding-left: 10px;
color: transparent;
cursor: pointer;
z-index: 5;
}
#search input[type=search]:hover {
background-color: #fff;
}
#search input[type=search]:focus {
width: 600px;
padding-left: 32px;
color: #4a83c0;
background-color: #fff;
cursor: auto;
}
#search input:-moz-placeholder {
color: transparent;
}
#search input::-webkit-input-placeholder {
color: transparent;
}
&#13;
<h3>Demo 2</h3>
<div class="right">
<img src="http://static.tumblr.com/ftv85bp/MIXmud4tx/search-icon.png" alt="" width="" height="" border="" align="" />
<img src="http://static.tumblr.com/ftv85bp/MIXmud4tx/search-icon.png" alt="" width="" height="" border="" align="" />
<form id="search">
<input type="search" placeholder="Search">
</form>
</div>
&#13;
答案 1 :(得分:0)
制作可展开的搜索栏position: absolute;
,它是父position: relative;
(因此可扩展栏位于其中)。然后,您可以使用填充来定位图像。
body {
background: #fff;
color: #666;
font: 90%/180% Arial, Helvetica, sans-serif;
width: 800px;
max-width: 96%;
margin: 0 auto;
}
/* START OF CHANGE */
.search-container {
position: relative;
padding-right: 40px;
}
#search input[type=search] {
position: absolute;
top: 0;
right: 0;
}
/* END OF CHANGE */
.right {
float: right
}
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] {
outline: none;
color: #4a83c0;
-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(http://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;
}
input[type=search]:focus {
width: 130px;
background-color: #fff;
border-color: #66CC75;
-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: #4a83c0;
}
input::-webkit-input-placeholder {
color: #4a83c0;
}
/* Demo 2 */
#search {
display: inline-block;
}
#search input[type=search] {
width: 15px;
padding-left: 10px;
color: transparent;
cursor: pointer;
}
#search input[type=search]:hover {
background-color: #fff;
}
#search input[type=search]:focus {
width: 600px;
padding-left: 32px;
color: #4a83c0;
background-color: #fff;
cursor: auto;
}
#search input:-moz-placeholder {
color: transparent;
}
#search input::-webkit-input-placeholder {
color: transparent;
}
<h3>Demo 2</h3>
<div class="right search-container">
<img src="http://static.tumblr.com/ftv85bp/MIXmud4tx/search-icon.png" alt="" width="" height="" border="" align="" />
<img src="http://static.tumblr.com/ftv85bp/MIXmud4tx/search-icon.png" alt="" width="" height="" border="" align="" />
<form id="search">
<input type="search" placeholder="Search">
</form>
</div>
答案 2 :(得分:0)
我用Javascript两个函数解决了你的问题。
如果未覆盖其他图像,请为要隐藏的图像指定ID。
继续在javascript部分添加这两个功能
// this will set the size of the images to 0px
function setImageWidthZero() {
document.getElementById("img1").style.width='0%';
document.getElementById("img2").style.width='0%';
}
// This will set the width to their default widths
function setImageWidthDefault() {
document.getElementById("img1").style.width='';
document.getElementById("img2").style.width='';
}
不要忘记给图片提供ID。
在输入字段中,您需要同时使用onblur和onClick方法。
<input type="search" placeholder="Search" onfocus='setImageWidthZero()'
onblur='setImageWidthDefault()'>
您可以复制的整个代码如下:
HTML部分
<h3>Demo 2</h3>
<div class="right">
<img src="http://static.tumblr.com/ftv85bp/MIXmud4tx/search-icon.png"
alt="" width="" height="" border="" align="" id='img1'/>
<img src="http://static.tumblr.com/ftv85bp/MIXmud4tx/search-icon.png"
alt="" width="" height="" border="" align="" id='img2'/>
<form id="search">
<input type="search" placeholder="Search" onfocus='setImageWidthZero()'
onblur='setImageWidthDefault()'>
</form>
</div>
CSS部分,你不需要在那里添加任何东西,你可以复制它 从您提供链接的网站。
如有任何问题,请告诉我。 享受编码。