search
HomeWeb Front-endHTML Tutorial【踩坑】近来在Firefox上遇到的一些坑 - 叶宇文羚

因为工作一年多以来,做的工作基本都是和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>

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

直到这次,真正遇到了问题。才在控制台上发现,原来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>

三)我擦,明明写了 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>

最后,还有些其他的

TO BE CONTINUED…

Statement
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
How do you set the lang attribute on the  tag? Why is this important?How do you set the lang attribute on the tag? Why is this important?May 08, 2025 am 12:03 AM

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

What is the purpose of HTML attributes?What is the purpose of HTML attributes?May 07, 2025 am 12:01 AM

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

How do you create a list in HTML?How do you create a list in HTML?May 06, 2025 am 12:01 AM

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

HTML in Action: Examples of Website StructureHTML in Action: Examples of Website StructureMay 05, 2025 am 12:03 AM

HTML is used to build websites with clear structure. 1) Use tags such as, and define the website structure. 2) Examples show the structure of blogs and e-commerce websites. 3) Avoid common mistakes such as incorrect label nesting. 4) Optimize performance by reducing HTTP requests and using semantic tags.

How do you insert an image into an HTML page?How do you insert an image into an HTML page?May 04, 2025 am 12:02 AM

ToinsertanimageintoanHTMLpage,usethetagwithsrcandaltattributes.1)UsealttextforaccessibilityandSEO.2)Implementsrcsetforresponsiveimages.3)Applylazyloadingwithloading="lazy"tooptimizeperformance.4)OptimizeimagesusingtoolslikeImageOptimtoreduc

HTML's Purpose: Enabling Web Browsers to Display ContentHTML's Purpose: Enabling Web Browsers to Display ContentMay 03, 2025 am 12:03 AM

The core purpose of HTML is to enable the browser to understand and display web content. 1. HTML defines the web page structure and content through tags, such as, to, etc. 2. HTML5 enhances multimedia support and introduces and tags. 3.HTML provides form elements to support user interaction. 4. Optimizing HTML code can improve web page performance, such as reducing HTTP requests and compressing HTML.

Why are HTML tags important for web development?Why are HTML tags important for web development?May 02, 2025 am 12:03 AM

HTMLtagsareessentialforwebdevelopmentastheystructureandenhancewebpages.1)Theydefinelayout,semantics,andinteractivity.2)SemantictagsimproveaccessibilityandSEO.3)Properuseoftagscanoptimizeperformanceandensurecross-browsercompatibility.

Explain the importance of using consistent coding style for HTML tags and attributes.Explain the importance of using consistent coding style for HTML tags and attributes.May 01, 2025 am 12:01 AM

A consistent HTML encoding style is important because it improves the readability, maintainability and efficiency of the code. 1) Use lowercase tags and attributes, 2) Keep consistent indentation, 3) Select and stick to single or double quotes, 4) Avoid mixing different styles in projects, 5) Use automation tools such as Prettier or ESLint to ensure consistency in styles.

See all articles

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

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.