我有一个 CSS 模板,我想在某些 HTML 标记中使用最少量的属性,同时允许稍后根据需要通过类(而不是 ID)轻松自定义该标记。
<ul data-role = 'a'>
<li>A</li>
<li>B</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
<style>
[data-role="a"] { /* ... */ }
[data-role="a"] > :first-of-type { /* ... */ }
[data-role="a"] > :last-of-type { /* ... */ }
</style>
Run Code Online (Sandbox Code Playgroud)
问题是,由于 CSS 的特殊性,我面临着要么制作所有选择器类,要么强制对我的内容进行任何样式表修改都非常具体:
<style>
[data-role="a"] > li { } /* custom overriding CSS */
</style>
Run Code Online (Sandbox Code Playgroud)
与
<ul class = 'a'>
<li class = 'a-top'>A</li>
<li class = 'a-bottom'>B</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
<style>
a {/* */}
a-top {/* */}
a-bottom {/* */}
</style>
Run Code Online (Sandbox Code Playgroud)
有没有办法在不使用 的情况下强制获得特异性产量 …
每当使用/TypeError调用非严格模式下的特定函数时,我都会抛出 a 。有一个部分解决方法是强制函数在严格模式下本地执行,但这是一个不完整的解决方案。nullundefined
var t = function(s) { console.log(this) };
t.call(null), t.call(undefined); // window, window
(function() {
"use strict";
t = function(s) { console.log(this) }
t.call(null), t.call(undefined); // null, undefined
})();
Run Code Online (Sandbox Code Playgroud)
我也不能抛出 if thisis ,因为该函数可以作为全局对象window合法地调用。this有没有不涉及的完整解决方法use strict?