3

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?

1
  • 2
    How your div can be 150px wide if you specify 100px ? Commented Feb 13, 2014 at 12:33

2 Answers 2

1

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).

Sign up to request clarification or add additional context in comments.

Comments

0

If you define status as a percentage (instead of fixed pixels) then you can do this with media queries

like so:

FIDDLE

.status {
    width: 20%;
    height: 100px;
    background: blue;
}
.status-icon {
    display: none;
    color: white;
}
/* 20% of 750px = 150px */
@media (min-width: 750px) {  
    .status-icon
    {
        display: block;
    }
}

So now when the viewport width hits 750px+ the status element will be 150px wide and with the media media query we can set .status-icon to block

1 Comment

I thought of this, but may be he is changing the width on the flow

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.