html - 将单击的按钮标记为活动的
问题描述
鉴于此 HTML:
<div class="wp-editor-tabs"><button type="button" id="bbp_topic_content-tmce" class="wp-switch-editor switch-tmce" data-wp-editor-id="bbp_topic_content">Visual</button>
<button type="button" id="bbp_topic_content-html" class="wp-switch-editor switch-html" data-wp-editor-id="bbp_topic_content">Text</button>
</div>
这是小提琴:小提琴
他们看起来像:
是否有可能,当单击一个按钮时,它会被激活,从而具有更厚的边框或其他指示符。然后,如果您单击另一个按钮,则该按钮显示为活动状态,而另一个按钮恢复正常样式?
此外,当页面第一次显示时,它会知道哪个显示为活动的。在上下文中,这些按钮与 bbPress 支持论坛和两个编辑器之间的切换有关。
可以用 CSS 实现我想做的事情吗?
解决方案
您可以使用 :focus,但在实践中它可能不会表现出您想要的样子。我建议改用 javascript/jQuery。
.wp-editor-tabs button:focus {
border:3px solid #000;
}
<div class="wp-editor-tabs">
<button type="button" id="bbp_topic_content-tmce" class="wp-switch-editor switch-tmce" data-wp-editor-id="bbp_topic_content">Visual</button>
<button type="button" id="bbp_topic_content-html" class="wp-switch-editor switch-html" data-wp-editor-id="bbp_topic_content">Text</button>
</div>
推荐阅读
- javascript - 如何在移动设备上不加载窗口事件侦听器?
- python - 如何按产生推理结果的模型 ID 组织推理结果?
- python - Python在错误的路径上创建文本文件
- qt - QGridLayout 中的项目不会换行
- firebase - 无法使用 vpc 无服务器连接器部署云功能
- blazor - 我可以分析从标签助手发送的参数吗?
- ansible - 创建收集托管主机信息并将它们写入每个主机上的文件的剧本
- python - 如何使用 openpyxl 将图像保存到 excel 文件中?
- google-chrome - 在没有活动选项卡权限的情况下使用 chrome 选项卡捕获/在没有用户输入的情况下获取活动选项卡权限
- python - 使用 Python 从 Google Drive 下载文件