html - 仅使用 css 更改 div 元素的颜色

标签 html css angular

我有以下按钮。 buttons .

post帮助我。但是,每次我点击其他任何东西时,按钮的颜色变化都会消失。我怎样才能让按钮保持橙色,直到我点击另一个按钮?

这是我的CSS:

.circle-button{
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: inline-block;
    background: var(--button-background, rgb(110, 109, 105));
    margin-left: 2px;
    margin-right: 2px;
    margin-top: 5px;
    margin-bottom: 5px
}

.circle-button:focus{
    outline: none;
    --button-background: rgb(231, 153, 8);
}
.circle-button:visited{
    --button-background: rgb(153, 13, 130);

这是我的 html:

<div class="circle-button" *ngFor="let record of imageRecords; let i = index" tabindex="{{i}}" ></div>

最佳答案

因为你使用的是 angular,所以对事件的 div 使用类:

CSS:

.circle-button{
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: inline-block;
    background: var(--button-background, rgb(110, 109, 105));
    margin-left: 2px;
    margin-right: 2px;
    margin-top: 5px;
    margin-bottom: 5px
}

.circle-button.active {
    outline: none;
    --button-background: rgb(231, 153, 8);
}

HTML:

<div class="circle-button" *ngFor="let record of imageRecords; let i = index" tabindex="{{i}}" [class.active]="currentTab == i" (click)="currentTab = i"></div>

关于html - 仅使用 css 更改 div 元素的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47656828/

相关文章:

html - 焦点时创建下拉菜单

jquery - 如何在 paginatorTemplate 中使用 {totalPages}?

json - Angular 7 HTTP GET 发送 JSON 对象作为参数

angular - Angular5 中具有动态内容的可重用模态

android - iOS 和 Android 中的视频播放功能

html - 将子 div 置于父 div 中心位置的 CSS 片段是什么——

html - 在 HTML ID 中使用数据库主键

javascript - 与 DropDownList 和 TexBox 元素的宽度相同

jquery - 透明背景iframe

angular - 服务中带有错误处理程序声明的基本Angular语法问题