简体   繁体   English

CSS 填充和边框半径未应用于移动设备

[英]CSS padding and border-radius not being applied on mobile

I have an email contact form, with a submit button, and some basic styling on the button.我有一个电子邮件联系表单,带有一个提交按钮,以及按钮上的一些基本样式。 All of the styles work on Desktop, and most of the styles are applied on mobile, just not the padding or border-radius.所有样式都适用于桌面,并且大多数样式都适用于移动设备,而不是填充或边框半径。 I already tried switching to EM units instead of pixels.我已经尝试切换到 EM 单位而不是像素。 The url is http://sharperprogrammer.com/contact (not self-promoting, just thought it would help to see the full thing)网址是http://sharperprogrammer.com/contact (不是自我宣传,只是认为这有助于查看完整内容)

HTML: HTML:

<input type="submit">

CSS: CSS:

input[type=submit] {
    background-color: #4CAF50;
    color: white;
    /* padding: 12px 20px; */
    padding: 1.2em 2em;
    border: none;
    border-radius: 0.4em;
    cursor: pointer;
    margin: 10px;
}

I have even connected my iPhone to my Mac and opened the Safari Developer Tools, and I can check and uncheck to toggle different styles on the button, but the padding seems to do nothing.我什至将我的 iPhone 连接到我的 Mac 并打开了 Safari 开发者工具,我可以选中和取消选中以在按钮上切换不同的样式,但填充似乎没有任何作用。 It's weird to me because the other styles like the background-color work fine, so I know everything is connected at least.这对我来说很奇怪,因为像背景颜色这样的其他样式工作正常,所以我知道至少所有东西都是相连的。 Thanks for taking a look!谢谢参观!

Edit : The style is just fine on an Android phone's Chrome browser, but the styling isn't applied correctly on my iPhone's Chrome or Safari browser.编辑:样式在 Android 手机的 Chrome 浏览器上很好,但样式在我的 iPhone 的 Chrome 或 Safari 浏览器上没有正确应用。 And I've cleared my browser cache just in case.为了以防万一,我已经清除了浏览器缓存。

Here is a screenshot:这是一个屏幕截图:

button_padding_not_applied

Try to add this:尝试添加这个:

  • in the navbar.css file inside media query :在媒体查询中的navbar.css文件中:
@media only screen and (max-width: 600px) {
.navbar{
    flex-direction: column;
    align-items: center;
}

}

It looks to me like Safari / Chrome Mobile have some default button styles that are more specific than input [type=submit] .在我看来,Safari / Chrome Mobile 有一些比input [type=submit]更具体的默认按钮样式。 Perhaps the more specific styles don't specify background-color which is why yours is working.也许更具体的样式没有指定背景颜色,这就是您的工作原理。

I found two solutions, which I will link below, that both vouch for adding -webkit-appearance: none;我找到了两个解决方案,我将在下面链接,它们都保证添加-webkit-appearance: none; as a solution.作为解决方案。

CSS submit button weird rendering on iPad/iPhone iPad/iPhone 上的 CSS 提交按钮奇怪的渲染

Why is my button style changing when on laptop and mobile 为什么我的按钮样式在笔记本电脑和移动设备上会发生变化

Hopefully this will work for you :)希望这对你有用:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM