如何将 wtforms 的 FileField 自定义为图像按钮?

编程入门 行业动态 更新时间:2024-10-28 09:13:40
本文介绍了如何将 wtforms 的 FileField 自定义为图像按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试从项目的文件夹中加载图像以用作图标而不是普通的选择文件".这是我迄今为止尝试过的.不仅图像没有加载,旧按钮只显示一半.

HTML

{{ form.tweet_image(class="submit-image-tweet")}}

CSS

.submit-image-tweet {背景: url(../templates/images/camera_icon.png) 不重复;光标:指针;边界:无;宽度:40px;高度:40px;}

解决方案

最简单的方法之一是将您的文件 input 包装到一个 label 中并为其设置样式.

关于样式化原生元素的跨浏览器规范正在改进.但是,如果您需要防弹支持,这仍然是最好的方法.

.file{显示:块;位置:相对;宽度:200px;高度:200px;背景:url(http://icons.iconarchive/icons/paomedia/small-n-flat/1024/device-camera-icon.png) 无重复中心;背景尺寸:封面;}.文件输入{不透明度:0;位置:绝对;顶部:0;右:0;底部:0;左:0;光标:指针;}

I'm trying to load an image from a project's folder to use as icon instead of the normal "choose file". Here's what I've tried so far. Not only the image isn't loaded, the old button is only displayed in half.

HTML

<div>{{ form.tweet_image(class="submit-image-tweet")}}</div>

CSS

.submit-image-tweet {
    background: url(../templates/images/camera_icon.png) no-repeat;
    cursor: pointer;
    border: none;
    width: 40px;
    height: 40px;
}

解决方案

One of the easiest ways is to wrap your file input into a label and style that instead.

The cross-browser spec on styling native elements is improving. However, if you need bullet-proof support, this is still the best way.

.file{
  display:block;
  position: relative;
  width: 200px;
  height: 200px;
  background: url(http://icons.iconarchive/icons/paomedia/small-n-flat/1024/device-camera-icon.png) no-repeat center center;
  background-size: cover;
}

.file input{
  opacity: 0;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  cursor: pointer;
}

<label class="file">
  <input type="file"/>
</label>

这篇关于如何将 wtforms 的 FileField 自定义为图像按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 09:14:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1132410.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   如何将   按钮   图像   FileField

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!