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

html-css010

上传图片的按钮能用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>

1、路径写错,这是一种常犯的错误。

2、CSS样式的选择器使用错误,这个原因只会造成部分没有样式,而不会造成整个网页没有样式

3、IIS安装问题

前两种原因,只能算是对代码的不熟悉。只能通过练习,熟练掌握 绝对路径和相对路径。才能避免这样的错误产生。后一种原因,可以重新安装IIS解决。

可以在CSS里面用background-image:url(你的图片地址)。这样来加入图片,展现到网页中。

<div id="bgimg"></div>

#bgimg {

background: #333 url(图片路径) center center no-repeat

}

第一个参数,图片底层的背景颜色,第二个参数,图片路径,第三个参数,图片上下的相对位置(其他参数left,right),第四个参数,图片左右的相对位置(top,bottom),第五个参数,图片的重复(其他参数 repeat,repeat-x,repeat-y)

扩展资料:

css背景图片代码:

{background-image: url(url)|none};指定要使用的一个或多个背景图像

例子代码:

<html>

<head>

<meta charset="UTF-8">

<title>背景图片</title>

<style>

body{background:#ddd}

.div1{

width:300px

height:150px

background-image:url(2.jpg)

}

</style>

</head>

<body>

<div>背景图片</div>

</body>