禁用的输入按钮 CSS 规则在 Mobile Safari 中不起作用
Disabled Input Button CSS Rules Not Working In Mobile Safari
我正在尝试使用 CSS :disabled 伪选择器来设置禁用按钮的样式。出于某种原因,使用 iOS Mobile Safari 时不遵守 "border-radius" 规则。我写了一个简单的 HTML 页面来演示问题(错误?)。以下示例适用于 Firefox、Chrome 和 IE/Edge,但不适用于 iPhone/iPod Touch。您可以通过 copy/pasting 将 HTML 代码转换为 https://www.w3schools.com/html/tryit.asp?filename=tryhtml_intro
来测试示例
向下滚动查看示例的屏幕截图:
<!DOCTYPE html>
<html>
<head>
<title>iOS Safari CSS But Demonstration</title>
<style>
input[type="button"],
input[type="submit"],
button,
input[type="button"]:disabled,
input[type="submit"]:disabled,
button:disabled {
min-width:300px;
cursor: pointer;
border-width: 1px;
border-style:solid;
border-color: rgba(0, 0, 0, 0.5);
color: #000000;
font-size: inherit;
padding: 2px 10px;
text-align: center;
opacity: 1;
/*
neither of the following border-radius rules
seem to work in iOS Safari
*/
border-radius: 0px !important;
-webkit-border-radius: 0px !important;
}
</style>
</head>
<body>
Disabled Input Example--the following disabled input<br/>
is supposed to have square corners (border-radius: 0px) but<br/>
instead they are rounded when viewed in an iOS Safari browser:<br/>
<input type="button" value="I should have square corners." disabled/>
</body>
</html>
iOS截图:
Firefox 截图:
为什么 "border-radius" CSS 禁用元素的规则在 iOS Mobile Safari 中不被遵守?
明白了:默认情况下,iOS Mobile Safari 会覆盖一些 CSS 规则(包括 border-radius)。要禁用此行为,请设置以下规则:
-webkit-appearance:none;
我正在尝试使用 CSS :disabled 伪选择器来设置禁用按钮的样式。出于某种原因,使用 iOS Mobile Safari 时不遵守 "border-radius" 规则。我写了一个简单的 HTML 页面来演示问题(错误?)。以下示例适用于 Firefox、Chrome 和 IE/Edge,但不适用于 iPhone/iPod Touch。您可以通过 copy/pasting 将 HTML 代码转换为 https://www.w3schools.com/html/tryit.asp?filename=tryhtml_intro
来测试示例向下滚动查看示例的屏幕截图:
<!DOCTYPE html>
<html>
<head>
<title>iOS Safari CSS But Demonstration</title>
<style>
input[type="button"],
input[type="submit"],
button,
input[type="button"]:disabled,
input[type="submit"]:disabled,
button:disabled {
min-width:300px;
cursor: pointer;
border-width: 1px;
border-style:solid;
border-color: rgba(0, 0, 0, 0.5);
color: #000000;
font-size: inherit;
padding: 2px 10px;
text-align: center;
opacity: 1;
/*
neither of the following border-radius rules
seem to work in iOS Safari
*/
border-radius: 0px !important;
-webkit-border-radius: 0px !important;
}
</style>
</head>
<body>
Disabled Input Example--the following disabled input<br/>
is supposed to have square corners (border-radius: 0px) but<br/>
instead they are rounded when viewed in an iOS Safari browser:<br/>
<input type="button" value="I should have square corners." disabled/>
</body>
</html>
iOS截图:
Firefox 截图:
为什么 "border-radius" CSS 禁用元素的规则在 iOS Mobile Safari 中不被遵守?
明白了:默认情况下,iOS Mobile Safari 会覆盖一些 CSS 规则(包括 border-radius)。要禁用此行为,请设置以下规则:
-webkit-appearance:none;