【发布时间】:2018-06-17 23:19:45
【问题描述】:
我有一个带有纯色背景的 div,其中包含一个表单。我在这个表单周围设置了 50px 的填充,并希望将纯色淡出为透明,以根据像素变量查看背后的背景。例如,如果我希望从表单到 div 边缘的所有内容都淡出,我可以选择 50px。或 45。或 25 等等。
当前 div:
我希望它是什么样子:
这个 div 的大小是可变的(高度:auto;),所以不幸的是,不可能只用一张图片作为背景。
我已经尝试在 Fiddle 上使用线性渐变修复它,但我没有使用它们的经验,我想我刚刚取消了所有内容。
HTML:
<div class="formBackground">
<form id="gform" method="POST" action="***">
<input type="text" id="name" name="name" placeholder="Name" style="width: 100%; float: left;">
<input type="text" id="email" name="email" placeholder="Email" style="width: 100%; float: left;">
<input type="textarea" id="message" name="message" placeholder="Write your message here..." style="width: 100%; float: left;">
</form>
</div>
CSS:
.formBackground {
top: 0px;
float: left;
margin-left: 50%;
transform: translateX(-50%);
width: 50%;
height: auto;
background-image : linear-gradient(to bottom,
rgba(55,54,51, 0),
rgba(55,54,51, 1) 90%);
background-image : linear-gradient(to left,
rgba(55,54,51, 0),
rgba(55,54,51, 1) 90%);
background-image : linear-gradient(to top,
rgba(55,54,51, 0),
rgba(55,54,51, 1) 90%);
background-image : linear-gradient(to right,
rgba(55,54,51, 0),
rgba(55,54,51, 1) 90%);
padding-left: 50px;
padding-top: 50px;
padding-right: 50px;
padding-bottom: 50px;
margin-top: 100px;
overflow: hidden;
margin-bottom: 4.5em;
}
提前致谢!
【问题讨论】:
标签: html css linear-gradients