html - 如何设置输入的背景透明度?

标签 html css

input[type="text"], input[type="password"]{
    opacity:0.5;
}

这会淡化输入主体和边框。我不希望边框透明,只希望主体透明,所以底层图像是可见的。当然,输入中的用户文本不应该是透明的。

input [type="submit"]{
    margin-left:50px;  // here nothing works at all.
}

最佳答案

opacity 属性影响整个元素的不透明度。你的问题有点含糊,但我假设你想要一个半透明的背景,而内容和边框不应该是透明的。

为此,您需要为元素设置半透明背景。这称为 alpha 透明度,因为第四个颜色 channel - alpha channel - 用于存储透明度信息(通常在 PNG 等图像中)。

在现代浏览器中,您可以为 background 属性使用 rgba() 值:

/* semi-transparent white background */
background: rgba( 255, 255, 255, .5 );

在 MS IE 中,您可以使用渐变滤镜,它从 MS IE 5 开始支持 ARGB 颜色。只需从颜色淡入淡出:(请注意,alpha channel 首先出现,所有四个颜色值都被标记为两个-数字十六进制)

/* the same for IE 7+8, should get included in a separate MS IE specific stylesheet */
background: none;
zoom: 1;
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr=#E5FFFFFF, endColorstr=#E5FFFFFF );
-ms-filter: progid:DXImageTransform.Microsoft.gradient( startColorstr=#E5FFFFFF, endColorstr=#E5FFFFFF );

关于html - 如何设置输入的背景透明度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14056881/

相关文章:

html - css 菜单子(monad)菜单水平

asp.net-mvc - Kendo 下拉列表隐藏在 Safari 中的 PDFViewer 后面

html - 如何使图库居中

PHP 运行 1/2 没有正确验证的 IF 语句

javascript - 如何维护 Bootstrap 选项卡上的分页?

python - 使用 Python 在 HTML 电子邮件中发送附件

html - 如何将事件类应用于引导选项卡用户界面

CSS距浏览器窗口的最小元素距离?

jquery - Bootstrap Horizo​​ntal NavBar 跨度页面宽度

jquery - 用HTML5和Canvas画出网站效果