javascript - Polymer 2.0 纸张输入文件自定义样式

标签 javascript html css polymer-2.x

我想为聚合物添加一些自定义样式 <paper-input type="file">

尝试过以下代码:

HTMLImports.whenReady(() => {
  Polymer({
    is: 'x-foo'
  });
});
<head>
  <base href="https://cdn.rawgit.com/download/polymer-cdn/2.6.0.2/lib/">
  <script src="webcomponentsjs/webcomponents-lite.js"></script>

  <link rel="import" href="polymer/polymer.html">
  <link rel="import" href="paper-input/paper-input.html">
  <link rel="import" href="iron-validator-behavior/iron-validator-behavior.html">
</head>

<body>
<x-foo></x-foo>
<dom-module id="x-foo">
<template>
<style>
paper-input.choose-file {
  --paper-input-container: {
    float: left;
    width: 150px;
    height: 50px;
    background: red;
    overflow: hidden;
  }
  --paper-input-container-underline: {
    border-color: transparent;
  }
  input[type="file"] {
      display: block !important;
      width: 150px !important;
      height: 50px !important;
      opacity: 0 !important;
      overflow: hidden !important;
    }
}
</style>
<paper-input type="file" class="choose-file"></paper-input>
</template>
  </dom-module>
</body>

类似于: https://jsfiddle.net/9sft3yd6/

谁能帮忙?

最佳答案

我认为您可以使用与链接相同的方式使用 iron-input 元素自定义输入。像这样的东西:

DEMO

<x-foo></x-foo>
<dom-module id="x-foo">
<template>
<style>
paper-input.choose-file {
  --paper-input-container: {
    float: left;
    width: 150px;
    height: 50px;
    background: green;
    overflow: hidden;
  }
  --paper-input-container-underline: {
    border-color: transparent;
  }
}

iron-input {
  padding: 10px;
  background: red;
  display: table;
  color: #fff;
}

input[type="file"] {
  display: none;
}

</style>
<paper-input type="file" class="choose-file"></paper-input>
  <br />  <br />  <br />  <br />  <br />  <br />  <br />  <br />  <br />  <br />  <br />  <br />
<iron-input>
  <label id="#bb"> Select Your File
  <input type="file" id="File"   size="60" > 
  </label>
</iron-input> 

</template>
  </dom-module>
</body>

关于javascript - Polymer 2.0 纸张输入文件自定义样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54231026/

相关文章:

jquery - 旋转箭头图像

java - HtmlUnit 属性未定义脚本错误

html - 如何在屏幕中间设置我的网站加载器

javascript - Angular 添加按钮不起作用

javascript - HTML 中的空文本

javascript - Jekyll 破坏 JSON 文件。箭头 ("=>")而不是 ":"

javascript - 如何将函数传递给 react 中的另一个组件

javascript - 使用 Ajax 附加到 Jade 中的下拉列表

javascript - 如何在javascript中有效解析xml

jquery - 表上的 SlideToggle JQuery 无法工作