css3怎么在input搜索框里添加图片

html-css012

css3怎么在input搜索框里添加图片,第1张

1、新建html文档。

2、书写hmtl代码。

<div class="container">

<div id="search">

<label for="search">点击查看效果(<a href="#" target="_blank">11111111111</a>):</label>

<input type="text" name="q">

<input class="button" type="submit" value="Search">

</div>

</div>

3、书写css代码。

<style>

body { background-color: #f1f1f1margin: 0}

body,  input,  button { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif}

.container { margin: 30px auto 40px autowidth: 800pxtext-align: center}

a { color: #4183c4text-decoration: nonefont-weight: bold}

a:hover { text-decoration: underline}

h3 { color: #666}

ul { list-style: nonepadding: 25px 0}

li { display: inlinemargin: 10px 50px 10px 0px}

input[type=text],  input[type=password] { font-size: 13pxmin-height: 32pxmargin: 0

padding: 7px 8pxoutline: nonecolor: #333background-color: #fffbackground-repeat:

no-repeatbackground-position: right centerborder: 1px solid #cccborder-radius: 3px

box-shadow: inset 0 1px 2px rgba(0,0,0,0.075)-moz-box-sizing: border-boxbox-sizing:

border-boxtransition: all 0.15s ease-in-webkit-transition: all 0.15s ease-in 0vertical-align: middle}

button { position: relativedisplay: inline-blockmargin: 0padding: 8px 15pxfont-size:

13pxfont-weight: boldcolor: #333text-shadow: 0 1px 0 rgba(255,255,255,0.9)white

space: nowrapbackground-color: #eaeaeabackground-image: -moz-linear

gradient(#fafafa, #eaeaea)background-image: -webkit-linear-gradient(#fafafa, #eaeaea)

background-image: linear-gradient(#fafafa, #eaeaea)background-repeat: repeat-x

border-radius: 3pxborder: 1px solid #dddborder-bottom-color: #c5c5c5box-shadow:

01px 3px rgba(0,0,0,.05)vertical-align: middlecursor: pointer-moz-box-sizing: border-box

box-sizing: border-box-webkit-touch-callout: none-webkit-user-select: none-khtml

user-select: none-moz-user-select: none-ms-user-select: noneuser-select: none

webkit-appearance: none}

.button:hover,  .button:active { background-position: 0 -15pxborder-color: #ccc #ccc

#b5b5b5}

.button:active { background-color: #dadadaborder-color: #b5b5b5background-image:

nonebox-shadow: inset 0 3px 5px rgba(0,0,0,.15)}

.button:focus,  input[type=text]:focus,  input[type=password]:focus { outline: noneborder

color: #51a7e8box-shadow: inset 0 1px 2px rgba(0,0,0,.075), 0 0 5px rgba(81,167,232,.5)}

label[for=search] { display: blocktext-align: left}

#search label { font-weight: 200padding: 5px 0}

#search input[type=text] { font-size: 18pxwidth: 705px}

#search .button { padding: 10pxwidth: 90px}

</style>

4、代码整体结构。

5、查看效果。

我们可以使用SVG、Canvas、CSS3或者背景图片来实现五角星图案及其悬停效果。

CSS3引入的伪元素和变换特性使得实现五角星图形非常简单,并且可以结合渐变实现更为漂亮的效果。

因此使用图片实现五角星已经毫无必要(图片占用额外的请求,且数据量大。除非要支持低版本的桌面IE浏览器)。

首先我们创建一个三角形,这通常是使用带大尺寸边线而零内容尺寸的元素来实现,代码示范:

.tri { width: 0height: 0border-left: 15px solid transparentborder-right: 15px solid transparentborder-bottom: 30px solid red}

第二步,我们使用伪元素:after和:before来克隆2个同样大小的三角形。

.tri:after,.tri:before { width: 0height: 0border-left: 15px solid transparentborder-right: 15px solid transparentborder-bottom: 30px solid red}

然后,我们在上述2个伪元素上分别应用不同的旋转变换:

.tri:before { transform: rotate(70deg)}.tri:after { transform: rotate(-70deg)}

这样我们就实现了一个五角星图形(图标)。我们可以用类似的方法实现更多的几何形状。

先说方法步骤:

首先创建一个三角形,使用带大尺寸边线而零内容尺寸的元素来实现。

使用伪元素:after和:before来克隆2个同样大小的三角形。

在上面所说的2个伪元素上分别应用不同的旋转变换来达到五角星效果。

代码如下:

<!--创建三角形-->

.tri {

width: 0

height: 0

border-left: 15px solid transparent

border-right: 15px solid transparent

border-bottom: 30px solid red

}

<!--使用伪类元素-->

.tri:after,.tri:before {

width: 0

height: 0

border-left: 15px solid transparent

border-right: 15px solid transparent

border-bottom: 30px solid red

}

<!--旋转-->

.tri:before {

transform: rotate(70deg)

}

.tri:after {

transform: rotate(-70deg)

}