Is it possible to define a CSS style for an element, that is only applied if the matching element contains a specific element (as the direct child item)?

I think this is best explained using an example.

**Note**: I'm trying to **style the parent element**, depending on what child elements it contains.

```
<style>
  /* note this is invalid syntax. I'm using the non-existing
   ":containing" pseudo-class to show what I want to achieve. */
  div:containing div.a { border: solid 3px red; }
  div:containing div.b { border: solid 3px blue; }
</style>

<!-- the following div should have a red border because
     if contains a div with class="a" -->
<div>
  <div class="a"></div>
</div>

<!-- the following div should have a blue border -->
<div>
  <div class="b"></div>
</div>

```

**Note 2**: I know I can achieve this using javascript, but I just wondered whether this is possible using some unknown (to me) CSS features.
['https://Stackoverflow.com/questions/2326499', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/19635/']
Basically, no. The following *would* be what you were after in theory:

```
div.a < div { border: solid 3px red; }

```

Unfortunately it doesn't exist.

There are a few write-ups along the lines of "why the hell not". A well fleshed out one by Shaun Inman is pretty good:

<http://www.shauninman.com/archive/2008/05/05/css_qualified_selectors>

Update. Many years later, :has has arrived, browser support is increasing.

<https://developer.mozilla.org/en-US/docs/Web/CSS/:has>

12 years is a long time.
In my case, I had to change the cell padding of an element that contained an input checkbox for a table that's being dynamically rendered with DataTables: 

```
<td class="dt-center">
    <input class="a" name="constCheck" type="checkbox" checked="">
</td>

```

After implementing the following line code within the [initComplete](https://datatables.net/reference/option/initComplete) function I was able to produce the correct padding, which fixed the rows from being displayed with an abnormally large height

```
 $('tbody td:has(input.a)').css('padding', '0px');

```

Now, you can see that the correct styles are being applied to the parent element: 

```
<td class=" dt-center" style="padding: 0px;">
    <input class="a" name="constCheck" type="checkbox" checked="">
</td>

```

Essentially, this answer is an extension of @KP's answer, but the more collaboration of implementing this the better. In summation, I hope this helps someone else because it works! Lastly, thank you so much @KP for leading me in the right direction!