如何将类应用于div的第一个按钮?
问题描述:
我有这个html,我想将类应用于DIV的第一个按钮。如何将类应用于div的第一个按钮?
<div class="button-container">
<button class="save" />
<button class="reset" />
</div>
我想将类添加到第一个按钮。
我想为此解决方案使用jQuery。
答
您可以像这样添加第二个类。
<div class="button-container">
<button class="save SecondClass" />
<button class="reset" />
</div>
+0
哈哈,它很简单,没有jQuery :) +1 – 2009-11-18 07:03:50
+0
我希望它是动态的。 – 2009-11-30 08:15:55
答
div.button-container > button:first-child { font-weight: bold; }
你想要一个适用于div中第一个按钮的CSS样式吗?然后SleighBoy有答案。 – andho 2009-11-18 08:31:42