• 知识点:定义input type=file 样式的方法(转)


      ——“当我们想要用css美化表单的时候,有两个控件就会和前段人员作对,一个是是大名鼎鼎的select,另一个就是我现在要说说的 input type=file”

    为什么要美化file控件?试想一下,别的孩子都穿戴整齐漂亮,其中两个孩子怎么都不鸟你,太不和谐了。

        原始的file控件是这样的:

      

     

    别以为这个是由一个text和一个button组合成的,它是一个控件,html代码为:

    <input type="file" name="file" /> 

     

    既然这样我们就用一个text和一个button来显示这个file的样式,html代码是这样: 

    <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> 

     

    外面的一层div是为了给里面的input提供位置参考,因为写样式的时候需要相对定位,使真正的file控件覆盖在模拟的上面,然后隐藏掉file控件(即使file控件不可见),所以css代码是这样的: 

    .file-box{ position:relative;width:340px} 
    .txt{ height:22px; border:1px solid #cdcdcd; width:180px;} 
    .btn{ background-color:#FFF; border:1px solid #CDCDCD;height:24px; width:70px;} 
    .file{ position:absolute; top:0; right:80px; height:24px; filter:alpha(opacity:0);opacity: 0;width:260px } 

     

    效果图:
    点击查看原图

    原文链接:http://www.jb51.net/web/39559.html

    
    —— 能力说话。
    —— 唯爱与美食不可负。
    —— 身体健康第一重要。
  • 相关阅读:
    HTML5保留的常用元素(三)
    HTML5保留的常用元素(二)
    HTML5保留的常用元素(一)
    vue项目打包部署到nginx 服务器上
    linux 前端部署
    window.open打开新窗口被浏览器拦截的处理方法
    windows java 环境变量配置
    npm 报错: npm ERR! Please try running this command again as root/Administrator.
    angular 之路由
    git 的日常使用命令
  • 原文地址:https://www.cnblogs.com/aileLiu/p/4108572.html
Copyright © 2020-2023  润新知