Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to target an element with specific css attribute (CSS Only Solution)?

I have an HTML snippet like below:

<div class="status">
    <div class="status-icon green">
      Online
    </div>
</div>

and related css:

.status {
  width: 100px;
}
.status-icon {
  display: none;
}

My question is:

How can I write a css rule when .status{width=150px} then .status-icon{display: block;}?

Or is there a selector to target specific css rules like attribute selectors?

like image 239
B.U Avatar asked Apr 20 '26 06:04

B.U


1 Answers

You cannot write a CSS rule where a property is set depending on whether the value of another property satisfies some condition. This seems to be what you are asking, even though you refer to CSS attributes. (There are no attributes in CSS; there are attribute selectors, but they refer to HTML or XML attributes.)

CSS as currently defined is simply a style sheet language with no programming features (or, let us say, with very limited programming-like features).

like image 188
Jukka K. Korpela Avatar answered Apr 22 '26 23:04

Jukka K. Korpela



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!