css-element-queries icon indicating copy to clipboard operation
css-element-queries copied to clipboard

Unexpected blinking!

Open 7iomka opened this issue 7 years ago • 5 comments
trafficstars

I'm using the latest version of the plugin in attempts to create a demo version of the button, which, in the case of long text, the font size is reduced by the given algorithm. But instead of the expected result, I see... https://codepen.io/7iomka/pen/RMyzyq

7iomka avatar Apr 02 '18 07:04 7iomka

Looks to me like you have created a loop, rethink your queries/steps and it will work.

marcj avatar Apr 02 '18 09:04 marcj

marcj, any ideas?:(

7iomka avatar Apr 02 '18 14:04 7iomka

@7iomka You could break the loop by giving the btn an explicit width, rather than having its width shrink-to-fit the size of its descendants: https://codepen.io/eeeps/pen/NYzYdm

The loop happens because you're querying the same thing you're conditionally styling. The btn__content font size shrinks, and so its shrinkwrapped btn parent shrinks, which makes the query false, which makes the btn__content font-size grow again, which makes the btn grow again which makes the query true, which...[repeat forever]

eeeps avatar Apr 02 '18 23:04 eeeps

@eeeps thanks for explanation and example! It works fine! But! I just wanted to use this plugin for buttons as independent components, the width of which I would not want to limit, I just use only paddings and font-size. I thought this plugin would help me do the following: I want the buttons that have the size of content, for example, do not fit 300 pixels, changed their font-size to the one I set, in which the content would already fit in one line. Naturally, I would do this only on mobile breakpoint. This is a kind of improvement of the UX of an independent component, which I wanted to do every time not to make an exception in the form of a hardcode over a certain button, the content of which was too long to fit on a certain width of the mobile :(

7iomka avatar Apr 03 '18 06:04 7iomka

@7iomka maybe a job for http://fittextjs.com ? Fundamentally, if you're trying to query AND change the same thing (here, the width of the text), you're going to have looping problems.

eeeps avatar Apr 03 '18 22:04 eeeps