我有两种不同类型的类名.第一个被命名color-*.例如:
color-red
color-blue
color-green
Run Code Online (Sandbox Code Playgroud)
我也有班级名字 hover-color-*
hover-color-red
hover-color-blue
hover-color-green
Run Code Online (Sandbox Code Playgroud)
我试图为默认的超链接颜色制作一个css规则:
a:not([class*='color-']) {
color: #3498db;
}
Run Code Online (Sandbox Code Playgroud)
这很好,但是如果存在这样的超链接:
<a href="#" class="hover-color-green">Link</a>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,超链接应该保留默认的超链接颜色,并且只应覆盖悬停颜色,但是由于规则class*='color-'和事实我只指定了悬停颜色,超链接没有给出正常颜色(#3498db).
有没有办法更新这个规则,以便它只在类名开头时触发color-?(所以,ANYTHING-color-不适用)
我试图使用JavaScript运行正则表达式检查,以确保字符串遵循模式:
NNNN-NNNN
(其中N =任意数字0-9)我需要确保破折号也就位.
因此,任何4个数字后跟一个破折号,后跟任意两个数字,后跟一个破折号,后跟任意两个数字.
如何将其写为正则表达式?
我试图从页面上的每个元素中删除一个特定的CSS类.我会做的事情如下:
$(body).removeClass('removethis');
$(body).each().removeClass('removethis');
Run Code Online (Sandbox Code Playgroud)
我不知道这样做的正确方法.我这样做是为了在启用javascript时自动从页面上的每个元素中删除一个类.
我有一个函数试图将 NULL 值传递给:
function test($this=null, $that=null) {
if ($this) {
// Do something
}
if ($that) {
// Do something else
}
}
Run Code Online (Sandbox Code Playgroud)
因此,如果我尝试仅为 传递值$that,我可以这样做:
$that = 100;
this('',$that);
Run Code Online (Sandbox Code Playgroud)
但是''将 NULL 传递给函数的最佳方法是什么呢?
当使用常量时,这是最佳实践,如果有的话?要将值设置为1/0或true/false?
define('CACHE_ENABLE', 0, true);
define('LOG_ENABLE', 1, true);
Run Code Online (Sandbox Code Playgroud)
要么
define('CACHE_ENABLE', false, true);
define('LOG_ENABLE', true, true);
Run Code Online (Sandbox Code Playgroud) 我试图在div中居中对齐列表,但保持文本左对齐.
因此,我希望所有子弹垂直排列(左对齐),但整个列表本身应位于中心,如下例中的段落所示:
.container { width: 600px; padding: 2em; background: #eee; }
.align-center { text-align: center; }Run Code Online (Sandbox Code Playgroud)
<div class="container">
<p class="align-center">Center Align Test</p>
<ul>
<li>First element</li>
<li>Second element</li>
<li>Finally, the third and final element</li>
</ul>
</div>Run Code Online (Sandbox Code Playgroud)