width: fit-content; working on Chrome but not explorer

I built an app and everything is displayed perfectly in Chrome, but if I open the app in Windows Explorer the containers are smaller than they should be.

I'm using width: fit-content. Is this something that only works with Chrome.

How can I make it so that it works with all browsers?

7 Answers

width: fit-content is still in experimental stages, and is currently supported on Chrome 46.x and above (without vendor prefix), FF 3.x and above (with vendor prefix). Not supported on either IE or edge.
You can refer to compatibility chart here: Browser compatibility for width:fit-content

One alternative is to use display: table, which has the same effect as width: fit-content. Of course, there are other ways that you can try depending on what your requirements are.

#fit-content { width: fit-content; background: pink; } #table { display: table; background: lightblue; } #normal { background: green; }
<div> <img src=""> fit-content </div> <div> <img src=""> table </div> <div> <img src=""> normal </div>
1

It can be done with width:auto but only when an element is display: inline-block as well as setting the value as right:inherit or left:inherit.

Example:

.my_div { width: auto; display: inline-block; right:inherit; /* align to left */ } 
0

Have similar problem. In one div, have others with display:inline-block

For parent div use white-space : nowrap;

Don't forget to set to child's div white-space : normal;

.parent { width: max-content; white-space : nowrap; } .parent .child { display: inline-block; white-space : normal; } 

HTML example

<div class='parent'> <div class='child'></div> <div class='child'></div> <div class='child'></div> </div> 

another alternative is to use width:auto; This works sometimes but it depends on your specific case.

I had a similar problem, fixed it this way. Instead of using width: fit-content; you can use the snippet below.

inline-flex is well supported (even on IE11).

In the example below, flex: none; is only useful if the parent is set as a display: flex;.

.element { display: inline-flex; flex: none; width: auto; } 

display: inline-table worked for me

1

ops! my answer came in 4yrs later.

I was building mobile page and had the issue with width: fit-content;. the code below worked for me:

header nav ul { display: table; margin: 0 auto; } 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like