【问题标题】:Disabled Input Button CSS Rules Not Working In Mobile Safari禁用的输入按钮 CSS 规则在移动 Safari 中不起作用
【发布时间】:2019-11-05 19:32:44
【问题描述】:

我正在尝试使用 CSS :disabled 伪选择器设置禁用按钮的样式。出于某种原因,使用 iOS Mobile Safari 时不遵守“边界半径”规则。我写了一个简单的 HTML 页面来演示这个问题(错误?)。以下示例适用于 Firefox、Chrome 和 IE/Edge,但不适用于 iPhone/iPod Touch。您可以通过将 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 截图:

火狐截图:

为什么 iOS Mobile Safari 不遵守禁用元素的“border-radius”CSS 规则?

【问题讨论】:

    标签: css css-selectors mobile-safari


    【解决方案1】:

    想通了:默认情况下,iOS Mobile Safari 会覆盖一些 CSS 规则(包括边框半径)。要禁用此行为,请设置以下规则:

    -webkit-appearance:none;
    

    https://developer.mozilla.org/en-US/docs/Web/CSS/appearance

    【讨论】:

      猜你喜欢
      • 2012-09-09
      • 1970-01-01
      • 2010-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-02
      • 2016-05-14
      • 1970-01-01
      相关资源
      最近更新 更多