plotly.js icon indicating copy to clipboard operation
plotly.js copied to clipboard

TailwindCSS breaks Plotly modebar layout

Open wuyuanyi135 opened this issue 4 years ago • 6 comments

When using Plotly together with TailWindCSS I noticed that the mode bar's layout is not correct: image Here is the codepen for reproducing this error.

I could confirm this was caused by the following rule that override the display property of .main-svg.

img, svg, video, canvas, audio, iframe, embed, object {
    display: block;
    vertical-align: middle;
}

I could fix this by adding this to override the CSS normalization behavior.

svg {
    display: inherit;
}

I noticed that the display property was block anyway. I don't understand how this inconsistency is caused. Do you think this is a bug?

wuyuanyi135 avatar Jul 16 '21 07:07 wuyuanyi135

I have this issue too, but svg{ display: inherit; } does not fix it for me.

tashburn avatar Dec 21 '21 07:12 tashburn

This is a fix:

.js-plotly-plot .plotly .modebar svg {
	display: inline;
}

or in svelte (which I'm using):

:global(.js-plotly-plot .plotly .modebar svg) {
	display: inline;
}

this is due to tailwind using css remedy style reset. The discussion about changing svg to block is here.

brendanmatkin avatar Mar 23 '23 19:03 brendanmatkin

Hi - we are trying to tidy up the stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for several years, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. Thanks for your help - @gvwilson

gvwilson avatar Jul 05 '24 11:07 gvwilson

I happened to run into this today and it's quite awkward. Since TailwindCSS is pretty popular, this is probably worth taking a look at.

TailwindCSS 3.4.3 Plotly 2.33.0 react-plotly.js 2.6.0

robertclaus avatar Jul 19 '24 03:07 robertclaus

thanks @robertclaus - I'll see if we can get this into one of the upcoming work cycles.

gvwilson avatar Jul 19 '24 14:07 gvwilson

I have the same issue but the fix is not enough. I use Tailwind v4.

Without preflight: Image

With preflight: Image

With preflight and @brendanmatkin's fix: Image

Any idea ?

EDIT: I just found that adding vertical-align: baseline; fixes it.

Final code:

.js-plotly-plot .plotly .modebar svg {
    display: inline;
    vertical-align: baseline;
}

guillaume-mueller avatar Apr 28 '25 08:04 guillaume-mueller