上传图片的按钮能用css写出自定义的样式吗

html-css09

上传图片的按钮能用css写出自定义的样式吗,第1张

1.可以利用css的定位元素来实现。

<style>

.btn{position: relativeoverflow: hiddenmargin-right: 4pxdisplay:inline-block*display:inlinepadding:4px 10px 4pxfont-size:14pxline-height:18px*line-height:20pxcolor:#ffftext-align:centervertical-align:middlecursor:pointerbackground-color:#5bb75bborder:1px solid #ccccccborder-color:#e6e6e6 #e6e6e6 #bfbfbfborder-bottom-color:#b3b3b3-webkit-border-radius:4px-moz-border-radius:4pxborder-radius:4px}

.btn input {position: absolutetop: 0 right: 0margin: 0border: solid transparentopacity: 0filter:alpha(opacity=0) cursor: pointer}

</style>

<div id="up_btn" class="btn">

<span>添加图片</span>

<input id="photoimg" type="file" name="photoimg">

</div>

非IE6浏览器,可以使用input:hover的伪类来控制样式,但IE6浏览器只能用JS来实现了,需要设定两个状态,然后用JS切换类。

<style>

#c_button { width:92pxheight:30px border:0float:left}

.c_up{background:url(../images/i_login_btn.png) no-repeat 0 top}

.c_down{background:url(../images/i_login_btn.png) no-repeat 0 bottom}

</style>

<input name="" id="c_button" class="c_up" type="submit" value="" title="点击登录"/>

<script type="text/javascript">

document.getElementById("c_button").onmouseover=function() {this.className = "c_down"}

document.getElementById("c_button").onmouseout=function(){this.className = "c_up"}

</script>

首先用PHOTOSHOP做出你想要的样式的图片。具体代码,我就把我以前写的CSS样式表发给你看看,仅供参考。 .btn1 {

height: 20px

width: 60px

background-image: url(img/search.jpg)

background-repeat: no-repeat

background-position: center center

background-color: transparent

border-top-style: none

border-right-style: none

border-bottom-style: none

border-left-style: none

}你只需要把背景图片更改成你的图片就可以了(需要注意图片文件和网页文件保存的位置)。