最近我发现自己经常使用jQuery和JavaScript,经常做我在使用CSS之前做的事情.
例如,我使用JavaScript/jQuery替换表行颜色或创建按钮和链接悬停效果.这可以接受吗?或者我应该继续使用CSS来做这些事情吗?
所以真正的问题是:当我使用太多jQuery时?当我越线时,我怎么能理解?
我见过一些开发人员写的
HTML:
<div class="test"> some content </div>
Run Code Online (Sandbox Code Playgroud)
CSS:
div.test {
width:100px.
}
Run Code Online (Sandbox Code Playgroud)
做的目的是什么,div.className而不仅仅是.className.
这是否意味着只有在将类应用于div时才应用此样式.
那么,<span class='test'>content</span>上面的css对'test'没有影响吗?如果是这样,这是最佳做法吗?这几乎就像样式覆盖不同类型的元素,混合风格与规则!
什么时候应该向元素添加类并使用类选择器对它们进行样式化,何时应该在父类上添加类/ id并按原样使用元素?
例:
<div class="warning-dialog">
<h3>This is the title</h3>
<p>This is the message</p>
</div>
.warning-dialog {}
.warning-dialog h3 {}
.warning-dialog p {}
Run Code Online (Sandbox Code Playgroud)
与
<div class="warning-dialog">
<h3 class="warning-title">This is the title</h3>
<p class="warning-message">This is the message</p>
</div>
.warning-dialog {}
.warning-title {}
.warning-message {}
Run Code Online (Sandbox Code Playgroud)
或者你应该这样做
.warning-dialog .warning-dialog {}
.warning-dialog .warning-title {}
.warning-dialog .warning-message {}
Run Code Online (Sandbox Code Playgroud)