我有一个实现为锚点的自定义按钮。该按钮具有图像和文本。

当按钮具有焦点时,我想为其设置不同的样式。具体来说,我想在图像和文字周围绘制一个虚线矩形。我还想另外基于另一个类设置样式。

这是按钮代码:

<a id="searchButton" class="button" href="#">
    <span class="icon-search"></span>
    Search
</a>


这是我的问题的CSS代码:

button:focus {
/*How do I make a rectangular dotted line around the button text and icon? /*
/* How do I refer to another class that has additional stylings? */
}

最佳答案

您具有“按钮”,但应改为“ .button”,因为您的标记不是按钮,而是类。

.button:focus {
  outline: #00FF00 dotted thick;
}


关于“我如何引用另一个具有其他样式的类?”这一问题,我相信您将需要一个SASS,LESS或其他动态样式表语言之类的库,因为CSS目前不支持该功能类型。

09-25 22:30
查看更多