【发布时间】:2019-05-11 16:30:09
【问题描述】:
出于某种原因,我无法让移动设备停止应用其默认样式并尊重引导 css (v3.4.1)。下面是我的html:
<div class="buttons col-xs-4">
<div id="btnvote1" class="btn-wrap row-md-4 mtop10 mbottom10">
<button class="btn-vote btn btn-secondary" onclick="vote(1)">Opt 1</button>
</div>
<div id="btnvote2" class="btn-wrap row-md-4 mbottom10">
<button class="btn-vote btn btn-primary" onclick="vote(2)">Opt 2</button>
</div>
<div id="btnvote3" class="btn-wrap row-md-4 mbottom10">
<button class="btn-vote btn btn-secondary" onclick="vote(3)">Opt 3</button>
</div>
<div id="btnvote4" class="btn-wrap row-md-4 mbottom10">
<button class="btn-vote btn btn-secondary" onclick="vote(4)">Opt 4</button>
</div>
</div>
我的 BundleConfig 在 _Layout.cshtml 中呈现
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate*"));
// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at https://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.min.css",
"~/Content/site.css"));
}
它在 PC 上的 Chrome 中的外观:
它在 Chrome 中的两个不同代 iPhone(5s、6)上的外观:
互联网一直告诉我应该有效,但我没有运气:
button, html input[type="button"], input[type="reset"], input[type="submit"] {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
任何建议表示赞赏
编辑:
解决方案
看来问题是假设btn-secondary 是引导程序提供的一个类。我实际看到的是 Buttons.Less 提供了一些样式(即灰色按钮背景)。 Buttons.Less 还将 webkit 外观设置为按钮,我认为这会导致移动设备覆盖为移动设备默认值并且不显示样式(如上所示,它忽略了灰色按钮背景)。
如果我使用 Bootstrap v3 btn 类之一,它会在移动设备上产生所需的结果
.btn
.btn-default
.btn-primary
.btn-success
.btn-info
.btn-warning
.btn-danger
.btn-link
每个人的小提琴示例都起作用的原因是因为他们使用的是 bootstrap v4,其中包括一个 btn-secondary 类。
【问题讨论】:
-
当您使用 Chrome 开发工具检查按钮时,您看到哪些样式应用于按钮?我的理解是你不应该应用这些外观属性。我的猜测是某处的其他一些 CSS 覆盖了按钮的引导样式。你能在 JSFiddle 和纯 HTML/CSS/JS 上模拟这个问题吗?
-
你能发布一个工作示例吗?如果我尝试使用您的代码重新创建它,它就可以正常工作。
-
我无法仅使用 JSFiddle 进行复制。 This 在我的移动测试设备上看起来不错。我想知道使用 cshtml 渲染捆绑配置是否会导致移动设备出现问题。不幸的是,由于我只有 iPhone 可以测试,所以我在检查源代码方面相当严格。
-
您的自定义样式可能存在问题。我试过this code。它在 Iphone 5s 和 7+ 中运行良好。
-
检查是否覆盖任何其他 btn 类。如果您执行 onclick 操作,则使用标签并将 btn class role=button 给他们
标签: css twitter-bootstrap razor mobile