Table of Contents
一)还在用 background-position-x
二)咦,为嘛还没开始输入文本框就验证变红了?
outline: 0可是然并卵啊" >三)我擦,明明写了 outline: 0可是然并卵啊
最后,还有些其他的
Home Web Front-end HTML Tutorial 【踩坑】近来在Firefox上遇到的一些坑 - 叶宇文羚

【踩坑】近来在Firefox上遇到的一些坑 - 叶宇文羚

May 22, 2016 pm 05:19 PM

因为工作一年多以来,做的工作基本都是和webkit系列打交道。

先是做m站,后来做了两个app内嵌的hybrid项目,从来只考虑webkit前缀和相关的伪类。

最近四个多月开始做内部的管理系统,写写样式,偶尔做个calendartree之类的组件,所有的基本只考虑新版Chrome。从来没考虑别的问题。

最近在帮人解决firefox下的一些兼容问题。QA妹纸提交了一堆“bug”Bug列表让人看了头疼,还有点心虚。囧。

按部就班,先打开控制台。一番研究,发现不少“bug”都是样式的问题,并不是脚本兼容做得不好。

下面就细数下最近发现的一些bug,算是做个备忘。以后还是得注意啊。

一)还在用 background-position-x

以前看一些CSS规范,反复强调不要使用background-position-x之类的属性。

百度FEX就指出:

4.6 2D 位置
[强制] 必须同时给出水平和垂直方向的位置。

<span class="hljs-comment" style="color: #999988; font-style: italic;">/* good */</span>
<span class="hljs-tag" style="color: #000080; font-weight: normal;">body</span> <span class="hljs-rules">{
    <span class="hljs-rule"><span class="hljs-attribute" style="color: #008080;">background-position</span>:<span class="hljs-value"> center top</span></span>; <span class="hljs-comment" style="color: #999988; font-style: italic;">/* 50% 0% */</span>
<span class="hljs-rule">}</span></span>
<span class="hljs-comment" style="color: #999988; font-style: italic;">/* bad */</span>
<span class="hljs-tag" style="color: #000080; font-weight: normal;">body</span> <span class="hljs-rules">{
    <span class="hljs-rule"><span class="hljs-attribute" style="color: #008080;">background-position</span>:<span class="hljs-value"> top</span></span>; <span class="hljs-comment" style="color: #999988; font-style: italic;">/* 50% 0% */</span>
<span class="hljs-rule">}</span></span>
Copy after login

一直以来恪守这个规则,但并没有深究原因。

直到这次,真正遇到了问题。才在控制台上发现,原来background-position-xFirefox下面是**无效**的!!!

二)咦,为嘛还没开始输入文本框就验证变红了?

第二个问题。

项目有个修改密码的表单。验证不通过的话,输入框会加上红色的边框。

然后QA妹纸在描述中说的是:

firefox浏览器中,修改密码页面,输入框中不输入任何字符,输入框颜色也是红的

我还以为又是哪里的js写得不对呢。找了半天,还是决定从样式入手。

Firefox的调试工具面板里,似乎只列出了样式表中的样式。浏览器默认样式的值,很难找到。我只能一点点试验。

最后发现,input输入框好像都带了个required属性。这是HTML5里表示表单元素必填的属性。莫非问题出在这里?试着删除了这个属性,果然解决了。

其实,这红色的边框,并不是border,而是box-shadow啊。

最后得到解决方案是加上这段CSS

<span class="hljs-tag" style="color: #000080; font-weight: normal;">input</span><span class="hljs-pseudo">:required</span><span class="hljs-pseudo">:invalid</span> <span class="hljs-rules">{
    <span class="hljs-rule"><span class="hljs-attribute" style="color: #008080;">box-shadow</span>:<span class="hljs-value"> none</span></span>;
<span class="hljs-rule">}</span></span>
Copy after login

三)我擦,明明写了 outline: 0可是然并卵啊

QA妹纸还反映,登录、注册等视图的各种按钮,在Firefox怎么点击之后,会出现黑色的边框啊?

啥?难道写代码的前端哥们儿不知道在:active:focus等状态下写个outline:0啊?这不科学。

于是又开始了神奇的探(gu)索(ge)之旅。

这次得到的答案是,这黑色的细线还真不是outline。这是一个奇怪的伪类,::-moz-focus-inner。简直哭死在键盘上。

于是,下面这段代码解决问题:

<span class="hljs-tag" style="color: #000080; font-weight: normal;">button</span><span class="hljs-pseudo">::-moz-focus-inner</span>,
<span class="hljs-tag" style="color: #000080; font-weight: normal;">input</span><span class="hljs-attr_selector">[type="reset"]</span><span class="hljs-pseudo">::-moz-focus-inner</span>,
<span class="hljs-tag" style="color: #000080; font-weight: normal;">input</span><span class="hljs-attr_selector">[type="button"]</span><span class="hljs-pseudo">::-moz-focus-inner</span>,
<span class="hljs-tag" style="color: #000080; font-weight: normal;">input</span><span class="hljs-attr_selector">[type="submit"]</span><span class="hljs-pseudo">::-moz-focus-inner</span>,
<span class="hljs-tag" style="color: #000080; font-weight: normal;">input</span><span class="hljs-attr_selector">[type="file"]</span> > <span class="hljs-tag" style="color: #000080; font-weight: normal;">input</span><span class="hljs-attr_selector">[type="button"]</span><span class="hljs-pseudo">::-moz-focus-inner</span> <span class="hljs-rules">{
    <span class="hljs-rule"><span class="hljs-attribute" style="color: #008080;">border-color</span>:<span class="hljs-value"> transparent</span></span>;
<span class="hljs-rule">}</span></span>
Copy after login

最后,还有些其他的

TO BE CONTINUED…

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1262
29
C# Tutorial
1235
24
Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

HTML, CSS, and JavaScript: Essential Tools for Web Developers HTML, CSS, and JavaScript: Essential Tools for Web Developers Apr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

HTML: The Structure, CSS: The Style, JavaScript: The Behavior HTML: The Structure, CSS: The Style, JavaScript: The Behavior Apr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML: Evolution and Trends in Web Design The Future of HTML: Evolution and Trends in Web Design Apr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML vs. CSS vs. JavaScript: A Comparative Overview HTML vs. CSS vs. JavaScript: A Comparative Overview Apr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

The Future of HTML, CSS, and JavaScript: Web Development Trends The Future of HTML, CSS, and JavaScript: Web Development Trends Apr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

See all articles