javascript - 自动完成移除边框
问题描述
我的表单关闭了自动完成功能,但所有现代浏览器都忽略了这一点。当用户输入他们的名字时,边框会保留,但当用户使用自动完成时,边框会被移除。
.half {
width: 50%;
margin-left: auto;
margin-right: auto;
}
input[type=name] {
width: 100%;
padding: 15px;
display: inline-block;
margin-bottom: 10px;
outline: none;
border-radius: 30px;
box-sizing: border-box;
border: solid 5px transparent;
background-image: linear-gradient(white, white), radial-gradient(circle at top right, #006699, #9900CC);
background-origin: border-box;
background-clip: padding-box, border-box;
font-family: 'Roboto', sans-serif;
font-size: 15px;
box-sizing: border-box;
}
.contain {
width: 100%;
min-width: 100%;
max-width: 100%;
min-height: 200px;
max-height: 200px;
margin-bottom: 10px;
background-image: linear-gradient(white, white), radial-gradient(circle at top right, #006699, #9900CC);
background-origin: border-box;
background-clip: padding-box, border-box;
border: solid 5px transparent;
border-radius: 30px;
padding: 0;
overflow: hidden;
box-sizing: border-box;
}
textarea {
width: 100%;
min-width: 100%;
max-width: 100%;
min-height: 200px;
max-height: 200px;
padding: 15px;
resize: none;
display: inline-block;
outline: none;
border: none;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
font-size: 15px;
border-radius: 30px;
box-sizing: border-box;
}
<div class="half">
<form method="post" name="submitted" action="submitted" autocomplete="off">
<input type="name" id="forename" name="forename" placeholder="Forename"><br>
<div class="contain">
<textarea></textarea>
</div>
<br>
<input type="submit" name="submit" id="submit" value="Contact Me" required="">
</form>
</div>
即使无法完全禁用自动完成,即使自动完成,我将如何维护边界。
解决方案
首先,没有办法(真的)影响background
Chrome 的任何陈述:-webkit-autofill
。我们可以操纵任何东西,但不能操纵background
. 我看到的唯一解决方案是input
用您的边框风格化边框覆盖父级。:-webkit-autofill
然后用规则技巧保护白色背景颜色。
虽然我换.contain
了一个.gradien
班。并改为type=name
(type=text
没有这种类型的广告name
)。
现在,即使您将切换autocomplete="on"
- 样式将与没有自动完成完全一样。为了保持渐变,你必须用类覆盖你input
和textarea
父元素中的所有内容.gradient
。
.half {
width: 50%;
margin-left: auto;
margin-right: auto;
}
.gradient {
background-image: linear-gradient(white, white), radial-gradient(circle at top right, #006699, #9900CC);
background-origin: border-box;
background-clip: padding-box, border-box;
border: solid 5px transparent;
border-radius: 30px;
margin-bottom: 10px;
overflow: hidden;
}
input[type=text] {
width: 100%;
padding: 15px;
margin: 0 !important;
display: inline-block;
margin-bottom: 10px;
outline: none;
box-sizing: border-box;
border: none;
background: #fff;
font-family: 'Roboto', sans-serif;
font-size: 15px;
box-sizing: border-box;
}
/* Change Autocomplete styles in Chrome*/
input[type=text]:-webkit-autofill,
input[type=text]:-webkit-autofill:hover,
input[type=text]:-webkit-autofill:focus {
/* this will protect agains the blue highlite */
-webkit-box-shadow: 0 0 0px 1000px #fff inset;
}
textarea {
width: 100%;
min-width: 100%;
max-width: 100%;
min-height: 200px;
max-height: 200px;
padding: 15px;
resize: none;
display: inline-block;
outline: none;
border: none;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
font-size: 15px;
border-radius: 30px;
box-sizing: border-box;
}
<div class="half">
<form method="post" name="submitted" action="submitted" autocomplete="off">
<div class="gradient"><input type="text" id="forename" name="forename" placeholder="Forename"></div>
<div class="gradient">
<textarea></textarea>
</div>
<br>
<input type="submit" name="submit" id="submit" value="Contact Me" required="">
</form>
</div>
推荐阅读
- oracle - V$SQLAREA 表包含 SQL_FULLTEXT,如何在 SQL_FULLTEXT 中找到 SQL 的来源
- javascript - 旋转后如何使脸部正常?
- html - 为什么 CSS flexbox 不能与媒体查询一起使用?
- java - 如何从 ArrayList<> 读取到 ArrayList<> 并将其打印到终端?
- html - 响应式两列社交媒体提要 flexbox
- javascript - 如何在html中附加javascript内容
- nlp - 是否可以在 Rasa Chatbot 中添加日期选择器?
- c# - 将 Angular 应用程序上传到 IIS
- php - 访问 CSS 文件中的 PHP 变量
- azure-pipelines - 由另一个构建触发的构建的构建源分支是否有 env var?