atanov,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
div[class~=test]:not([class~=red]){
background-color: #006400;
}
div[class~=test][class~=red]{
background-color: #FF0000;
}
</style>
</head>
<body>
<div class="test red">01</div>
<div class="test">02</div>
<div class="test red">03</div>
<div class="test">04</div>
<div class="test red">05</div>
</body>
</html>