如何用css3设置去除file默认效果

html-css05

如何用css3设置去除file默认效果,第1张

这个不能去除;

file是由一个text和一个button组合成的;既然这样我们就用一个text和一个button来显示这个file的样式;

<html>

<head>

<meta http-equiv="Content-Type" content="text/html charset=utf-8" />

<title>定义input type="file" 的样式</title>

<style type="text/css">

body{ font-size:14px}

input{ vertical-align:middle margin:0 padding:0}

.file-box{ position:relativewidth:340px}

.txt{ height:22px border:1px solid #cdcdcd width:180px}

.btn{ background-color:#FFF border:1px solid #CDCDCDheight:24px width:70px}

.file{ position:absolute top:0 right:80px height:24px filter:alpha(opacity:0)opacity: 0width:260px }

</style>

</head>

<body>

<div class="file-box">

  <form action="" method="post" enctype="multipart/form-data">

 <input type='text' name='textfield' id='textfield' class='txt' />  

 <input type='button' class='btn' value='浏览...' />

    <input type="file" name="fileField" class="file" id="fileField" size="28" onchange="document.getElementById('textfield').value=this.value" />

 <input type="submit" name="submit" class="btn" value="上传" />

  </form>

</div>

</body>

</html>

CSS是Cascading Style Sheet 的缩写。译作「层叠样式表单」。是用于(增强)控制网页样式并允许将样式信息与网页内容分离的一种标记性语言。链入外部样式表文件 (Linking to a Style Sheet) 你可以先建立外部样式表文件(.css),然后使用HTML的link对象。示例如下: <head><title>title of article</title><link rel=stylesheet href=" http://baike.baidu.com/css/font.css" type="text/css"></head>而在XML中,你应该如下例所示在声明区中加入: <? xml-stylesheet type="text/css" href=" http://baike.baidu.com/css/font.css" ?>>定义内部样式块对象 (Embedding a Style Block) 你可以在你的HTML文档的<HTML>和<BODY>标记之间插入一个<STYLE>...</STYLE>块对象。 定义方式请参阅样式表语法。示例如下: <html><style type="text/css"><!-- body {font: 10pt "Arial"} h1 {font: 15pt/17pt "Arial"font-weight: boldcolor: maroon} h2 {font: 13pt/15pt "Arial"font-weight: boldcolor: blue} p {font: 10pt/12pt "Arial"color: black} --></style><body>请注意,这里将style对象的type属性设置为"text/css",是允许不支持这类型的浏览器忽略样式表单。 内联定义 (Inline Styles) 内联定义即是在对象的标记内使用对象的style属性定义适用其的样式表属性。示例如下: 这一行被增加了左右的外补丁 样式表语法 (CSS Syntax) Selector { property: value } 参数说明: Selector -- 选择符 property : value -- 样式表定义。属性和属性值之间用冒号(:)隔开。定义之间用分号()隔开 继承的值 (The ' Inherit ' Value) 每个属性都有一个指定的值:Inherit。它的意思是:将父对象的值等同为计算机值得到。这个值通常仅仅是备用的。显式的声明它可用来强调。 选择符说明: #表示选择id .表示选择class 比如我有个 这时就得用#test{属性}来给id为test的div来制定样式 而 则应该用.test{属性}来给其指定样式。 编辑本段根据分辨率不同,调用不同的css文件 dottedTABLE-LAYOUT: fixedBORDER-TOP: #cccccc 1px dottedBORDER-LEFT: #cccccc 1px dottedBORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0><SCRIPT LANGUAGE="javascript"><!-- if (window.navigator.userAgent.indexOf("MSIE")>=1) { var IE1024=""var IE800=""var IE1152=""var IEother=""ScreenWidth(IE1024,IE800,IE1152,IEother) }else{ if (window.navigator.userAgent.indexOf("Firefox")>=1) { file://如果浏览器为Firefox var Firefox1024=""var Firefox800=""var Firefox1152=""var Firefoxother=""ScreenWidth(Firefox1024,Firefox800,Firefox1152,Firefoxother) }else{ file://如果浏览器为其他 var Other1024=""var Other800=""var Other1152=""var Otherother=""ScreenWidth(Other1024,Other800,Other1152,Otherother) } } function ScreenWidth(CSS1,CSS2,CSS3,CSS4){ if ((screen.width == 1024) &&(screen.height == 768)){ setActiveStyleSheet(CSS1)}else{ if ((screen.width == 800) &&(screen.height == 600)){ setActiveStyleSheet(CSS2)}else{ if ((screen.width == 1152) &&(screen.height == 864)){ setActiveStyleSheet(CSS3)}else{ setActiveStyleSheet(CSS4)}}} } function setActiveStyleSheet(title){ document.getElementsByTagName("link")[0].href="style/"+title} file://--></SCRIPT>解释: var IE1024=""var IE800=""var IE1152=""var IEother=""引号里面分别填写,用户使用IE的时候并且分辨率为1024*768,800*600,1152*864要使用的css文件名. var Firefox1024=""var Firefox800=""var Firefox1152=""var Firefoxother=""引号里面分别填写,用户使用FF的时候并且分辨率为1024*768,800*600,1152*864要使用的css文件名. var Other1024=""var Other800=""var Other1152=""var Otherother=""引号里面分别填写,用户使用其他浏览器的时候并且分辨率为1024*768,800*600,1152*864要使用的css文件名. 不判断分辨率,只判断浏览器 应E.Qiang提议,编如下代码。实现根据浏览器类型自动调用不同CSS。 代码: <SCRIPT LANGUAGE="javascript"><!-- if (window.navigator.userAgent.indexOf("MSIE")>=1) { file://如果浏览器为IE setActiveStyleSheet("default.css")}else{ if (window.navigator.userAgent.indexOf("Firefox")>=1) { file://如果浏览器为Firefox setActiveStyleSheet("default2.css")}else{ file://如果浏览器为其他 setActiveStyleSheet("newsky.css")} } function setActiveStyleSheet(title){ document.getElementsByTagName("link")[0].href="style/"+title} file://--></SCRIPT>解释: 如果浏览器为IE,则调用default.css 如果浏览器为Firefox,则调用default2.css 如果浏览器为其他,则调用newsky.css 用法:放在<head></head>中即可。 中国专业css标准化推广网站 【Div之家】 www.divhome.com======================================================================= css 层叠样式表 引入层叠样式表的方法包括: 1,外联式样式表 2,内嵌样式表 3,元素内定 4,导入样式表 外联式样式表 例:<head><link rel="stylesheet" href="/css/default.css"></head><body>.... </body></html>属性:rel 用来说明<link>元素在这里要完成的任务是连接一个独立的css文件。而href属性给出了所要连接css文件的url地址 内嵌式样式表: 例:<html><head><style type="text/css"><!-- td{font:9ptcolor:red} .font105{font:10.5ptcolor:blue} --></style></head><body>....</body></html>元素内定 格式: 导入式样式表 〈html><head><style type="text/css"><!-- @import url(css/home.css)--></style><body>.... </body></html>