2012-05-06 60 views
0

我改變了輸入文件按鈕樣式與jquery,但我需要文本輸入和按鈕之間的空間。輸入類型文件樣式

我該怎麼辦?

我使用本教程:http://www.appelsiini.net/projects/filestyle

+1

文件輸入都幾乎是不可能的風格。大多數人將它們隱藏起來,然後在其上面加上其他東西,並在其上添加樣式。 –

+0

編輯filestyle javascript,並編輯.css函數,或者添加一些類到button元素並使用樣式表進行樣式化 –

回答

1

您可以編輯JavaScript源代碼,添加一些利潤率左像我一樣(「保證金左:」 8像素「),

嘗試這樣的:

/* 
* Style File - jQuery plugin for styling file input elements 
* 
* Copyright (c) 2007-2008 Mika Tuupola 
* 
* Licensed under the MIT license: 
* http://www.opensource.org/licenses/mit-license.php 
* 
* Based on work by Shaun Inman 
* http://www.shauninman.com/archive/2007/09/10/styling_file_inputs_with_css_and_the_dom 
* 
* Revision: $Id: jquery.filestyle.js 303 2008-01-30 13:53:24Z tuupola $ 
* 
*/ 

(function($) { 

    $.fn.filestyle = function(options) { 

     /* TODO: This should not override CSS. */ 
     var settings = { 
      width : 250 
     }; 

     if(options) { 
      $.extend(settings, options); 
     }; 

     return this.each(function() { 

      var self = this; 
      var wrapper = $("<div>") 
          .css({ 
           "width": settings.imagewidth + "px", 
           "height": settings.imageheight + "px", 
           "background": "url(" + settings.image + ") 0 0 no-repeat", 
           "background-position": "right", 
           "display": "inline", 
           "position": "absolute", 
           "overflow": "hidden" 
           "margin-left:"8px", 
          }); 

      var filename = $('<input class="file">') 
          .addClass($(self).attr("class")) 
          .css({ 
           "display": "inline", 
           "width": settings.width + "px" 
          }); 

      $(self).before(filename); 
      $(self).wrap(wrapper); 

      $(self).css({ 
         "position": "relative", 
         "height": settings.imageheight + "px", 
         "width": settings.width + "px", 
         "display": "inline", 
         "cursor": "pointer", 
         "opacity": "0.0" 
        }); 

      if ($.browser.mozilla) { 
       if (/Win/.test(navigator.platform)) { 
        $(self).css("margin-left", "-142px");      
       } else { 
        $(self).css("margin-left", "-168px");      
       }; 
      } else { 
       $(self).css("margin-left", settings.imagewidth - settings.width + "px");     
      }; 

      $(self).bind("change", function() { 
       filename.val($(self).val()); 
      }); 

     }); 


    }; 

})(jQuery); 
+0

我沒有得到任何東西想想你的代碼,你可以給我一個鏈接或什麼來解釋給我,我是一個初學者,我不覺得每一個想法 – Houx