use initial width for element not working in IE

CssInternet ExplorerCross BrowserWidth

Css Problem Overview


I have a graph plugin that inserts canvas and a legend <table> to its container. In this plugin the table has no width defined and in my CSS there is a width for tables inside that container were my plugin gets inserted.

So, the new div is inheriting table{ width: 100%} from the CSS and rendering wrong.

I tried to use width: initial;, looks good on Chrome but IE doesn't like it check browser compatibility

I admit changing/forcing a inline CSS in the script/plugin since it has to work in any enviroment.

What is the best solution here?

Css Solutions


Solution 1 - Css

Like you said, generally width: auto will have a similar effect. Having the rules:

.my-selector {
    width: auto;
    width: initial;
}

Should cause it to use initial if it's supported and auto otherwise.

Solution 2 - Css

Using width: auto; inline, inside the script solves the problem on Chrome, FIrefox and IE 11. Just not sure if there is a better way.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRikardView Question on Stackoverflow
Solution 1 - CssMark RhodesView Answer on Stackoverflow
Solution 2 - CssRikardView Answer on Stackoverflow