Home  >  Article  >  Web Front-end  >  Why Do Styles Disappear When Using `title` Attributes in `` Tags?

Why Do Styles Disappear When Using `title` Attributes in `` Tags?

Linda Hamilton
Linda HamiltonOriginal
2024-10-28 12:01:01441browse

Why Do Styles Disappear When Using `title` Attributes in `` Tags?

Why are Styles Ignored When the 'title' Attribute is Used?

In the HTML provided:

<code class="html"><link rel="stylesheet" media="screen" type="text/css" title="A" href="a.css" />
<link rel="stylesheet" media="screen" type="text/css" title="B" href="b.css" /></code>

The b.css styles are not applied because the title attribute is present. According to the HTML specification, stylesheets can be one of three types:

  • Persistent: Linked with rel="stylesheet" without a title attribute. These stylesheets are always used for rendering.
  • Preferred: Linked with rel="stylesheet" and a title attribute. Preferred stylesheets with the same title are grouped together. However, browsers typically only select one preferred stylesheet to render.
  • Alternate: Linked with rel="alternate stylesheet" and a title. These stylesheets allow users to choose from different styles and are displayed in the browser's stylesheet selector (if available). Stylesheets grouped by the same title in this category are mutually exclusive.

By adding title attributes to the stylesheets, they are inadvertently converted from persistent stylesheets to preferred stylesheets. Since there are two preferred stylesheets with different titles, browsers are forced to choose one, resulting in the non-application of the b.css styles. This issue is resolved when both stylesheets have the same title because they are then grouped together as one preferred stylesheet.

The above is the detailed content of Why Do Styles Disappear When Using `title` Attributes in `` Tags?. For more information, please follow other related articles on the PHP Chinese website!

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