1

Can I use Media queries with current div style maybe like that:

.myDiv {
  anyStyle : ...;

  @media (myDiv's width > 100px) {
    height: 40px;
  }

}

I found several pages,but there said only using window params. if anybody know how to use the media, please tell me about I saw the links:

  1. http://www.w3schools.com/css/css_mediatypes.asp
  2. https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries
  3. http://mobile.smashingmagazine.com/2010/07/19/how-to-use-css3-media-queries-to-create-a-mobile-version-of-your-website/
5
  • Actually, your question is an XY problem. Please, explain what is your point here. I mean what are you trying to achieve, really. Commented Nov 20, 2013 at 12:44
  • in my case div depends on div's scale, and scale does not relate to window width Commented Nov 20, 2013 at 12:55
  • Do you mean you want to set the height of the .myDiv relatively to its width? Commented Nov 20, 2013 at 12:58
  • I don't get it. The div stays with the same width, right? Then what did you mean by scale in your previous comment? Commented Nov 20, 2013 at 13:39
  • Can you not simply set the height constant too? The scale is applied only after the width/height is set, so what is the point in finding out what the width is after the transformation? Commented Nov 20, 2013 at 14:03

2 Answers 2

4

No.

You can't use media queries to check the width of an item on your website. Media queries only check the viewport variables like width and height. You should use them to check what kind of screen your user has and not what style you have applied to your div.

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

Comments

2

You should do it that way:

.myDiv {
    /* your styles */
}

@media only screen (min-width: 100px) {
    .myDiv {
        /* other styles */
    }
}

The only way to work with media queries is to rely on device type (screen, print etc.) and/or device width (min-width, max-width).

3 Comments

does min-width mean `myDiv.width' ?
@UlugbekKomilovich no. It means window width.
realy, is there no way how to make it

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.