我正在使用angularjs,以下是我的css
table {
border: 1px solid black;
padding: 0.5em;
}
td {
padding: 1em;
border: 2px solid gray;
}
td:hover {
cursor: default;
background-color: gray;
}
.active {
border: 2px solid lightgreen;
border-radius: 5px;
}
.booked {
background-color: lightgray;
}
.no_seat {
padding: 0em;
border: 2px white;
background-color: white;
}
.filled {
background-color: teal;
}
我想删除td:hover效果,如果它是no_seat我删除了单元格的边框,如果no_seat通过重置填充和边框但不知道如何删除悬停效果。
以下是我的index.html
<div ng-app="bookYourSeatApp" ng-controller="mainCtrl as ctrl">
<label>Persons <select ng-model="ctrl.selectedCount" ng-change="ctrl.seats.setAvailCount(ctrl.selectedCount)" ng-options="count as count.val for count in ctrl.selectionCount"></select></label>
Seats left: {{ctrl.seats.availCount}}<br/>
Seats selected: {{ctrl.seats.checkedSeats}}<br/>
<table ng-repeat="(key, rang) in ctrl.seats.map">
<tr ng-repeat="row in rang.seats">
<td ng-repeat="seat in row" ng-class="{'active': seat.checked, 'booked': seat.status == 'UNAVAILABLE', 'no_seat': seat.status == 'NO_SEAT', 'filled': seat.status == 'FILLED'}" ng-click="ctrl.seats.select({rang:key, row:row, seat: seat}, ctrl.selectedCount)">
{{seat.caption}}
</td>
</tr>
</table>
</div>
答案 0 :(得分:4)
如果我理解你的问题,可以用纯css完成。
结合你的css选择器:
td:hover {
cursor: default;
background-color: gray;
}
.no_seat {
padding: 0em;
border: 2px white;
background-color: white;
}
/* this will control the "no_seat" hovered styles */
td.no_seat:hover {
background-color: white;
/* any other styles you want here */
}
正如@ricky_ruiz在他的回答中指出的那样,你也可以使用:not()
伪选择器,但是如果你有其他类你希望它不影响的IMO会变得复杂...
答案 1 :(得分:3)
您正在寻找:not
伪类。
否定CSS伪类:不是(X),是一种功能符号 将一个简单的选择器 X作为参数。它匹配一个元素 没有参数表示。 X不得包含另一个 否定选择器。
改变这个:
td:hover {
cursor: default;
background-color: gray;
}
对此:
td:not(.no_seat):hover {
cursor: default;
background-color: gray;
}