JSFiddle - React, Tailwind, and code Playground
HTML
<div class="hidden">
<input name="bar-foo" value="test">
</div>
<div class="hidden">
<input name="bar-foo-baz" value="test2">
</div>
<div class="nothidden">
<input name="bar-foo" value="test3"> <!-- should be selected -->
</div>
<div class="nothidden">
<input name="foo-bar-baz" value="test4"> <!-- should be selected -->
</div>
CSS
:not(.hidden) input[name*="foo"][name*="bar"] {
color:blue;
}