加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

html – 具有“type”属性与make-up属性的CSS属性选择器和区分大

发布时间:2020-12-14 18:43:21 所属栏目:资源 来源:网络整理
导读:我正在尝试根据其type属性设置OL样式.所有UL和OL的列表样式属性之前已经被另一个我无法修改的CSS样式表消灭了,我需要重新设置列表样式,将类型考虑在内,即如果OL应该使用Roman人物或字母数字等 我想,这很容易;我将使用属性选择器根据type属性的值来定位OL.属
我正在尝试根据其type属性设置OL样式.所有UL和OL的列表样式属性之前已经被另一个我无法修改的CSS样式表消灭了,我需要重新设置列表样式,将类型考虑在内,即如果OL应该使用Roman人物或字母数字等

我想,这很容易;我将使用属性选择器根据type属性的值来定位OL.属性选择器区分大小写,所以这应该很简单,对吧?

错 – 至少在您尝试使用标准“类型”属性时.

这是一个例子(有效):

/* Remove default list style */
ul,ol { list-style:none; }

/* This works,using a non-standard foo attribute. The selector is case sensitive,so I can target 'i' and 'I' separately */
ol[foo='i'] {
  list-style-type:lower-roman;
}

ol[foo='I'] {
  list-style-type:upper-roman;
}
<ol foo="i">
  <li>Styled with lower case roman</li>
  <li>Styled with lower case roman</li>
</ol>

<ol foo="I">
  <li>Styled with uppercase roman</li>
  <li>Styled with uppercase roman</li>
</ol>

现在,用类型替换foo并再试一次:

/* Remove default list style */
ul,ol { list-style:none; }

/* Trying to use the standard type attribute,the selector is no longer case sensitive,so I cannot style 'i' and 'I' individually .... */
ol[type='i'] {
  list-style-type:lower-roman;
}

ol[type='I'] {
  list-style-type:upper-roman;
}
<ol type="i">
  <li>Should be lower-case roman</li>
  <li>Should be lower-case roman</li>
</ol>

<ol type="I">
  <li>Should be upper-case roman</li>
  <li>Should be upper-case roman</li>
</ol>

现在它就像选择器不再区分大小写,并且两个列表都受到影响,并且都使用大写罗马.

我无法找到任何关于这是否是正确行为的信息,也就是说,使用非标准属性(如’foo’)使用已知属性(如’type’v.s)时.在Chrome和Firefox中都会发生这种情况的事实让人相信它不是一个错误.

有任何想法吗?

这是一个混乱的CodePen:https://codepen.io/haukurhaf/pen/NOQYOz

解决方法

这个以及强制属性选择器匹配区分大小写的更广泛的用例已在 the introduction of a case-sensitive attribute selector flag s中得到解决:
ol[type='i' s] {
  list-style-type:lower-roman;
}

ol[type='I' s] {
  list-style-type:upper-roman;
}

现在我们等待实施……

HTML规范似乎表明ol的type属性的行为是不正确的,但是它对某些关键字的使用使得它不到100%清晰. Section 4.16.2使用“必须”:

Attribute selectors on an HTML element in an HTML document must treat the values of attributes with the following names as ASCII case-insensitive,with one exception as noted 07002:

  • type (except as specified in the rendering section)

All other attribute values and everything else must be treated as entirely case-sensitive for the purposes of selector matching.

并指向section 14.3.8,它使用abstract of section 14中描述的“预期”(tl; dr:浏览器不一定违反规范,如果它选择不遵循所谓的“预期”行为):

The following rules are also expected to apply,as presentational hints:

06001

In the above style sheet,the attribute selectors for the ol and li elements are expected to be treated as case-sensitive.

鉴于后者所描述的预期行为更符合作者的期望,而不是实际的浏览器行为,我会说尽管“预期”一词具有允许性,但这确实是不正确的行为.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读