[英]max-width not working in IE11 with display: table container and display: flex children
在下面的代碼中,所有內容均可在Chrome中正確顯示。 .inner
元素max-width
受max-width
限制。
在IE11中, .inner
元素擴展到所有內容。
如果我設置.container
或.inner
元素的display: block
, .container
都可以正常工作。 但是我不能這樣做,因為此示例是在許多站點上使用的大型組件中的錯誤的簡短再現,我不想破壞某些內容。
.container { background-color: yellow; display: table; height: 100px; max-width: 277px; } .inner { background-color: red; display: flex; height: 50px; }
<div class="container"> <div class="inner">77 777 777 77 7 7777 77 7 7 7 77 7 7 7 77 7 7 7 7 7 77 7 7 7 7 77 7 77 7 7 77 7 7 77 7 7 77 7 7 77 7 7 7 7 7</div> <div class="inner">111 11111 111111111111 111111111111 111111111 111111111111 11111111111 11111111111 11111111 1111111111 11111</div> </div>
一般來說,您可以預期IE11中的flexbox會出現問題 。
放入<table>
元素作為flex容器的父級(通常,表的子級是表單元格),現在您正在尋找麻煩。
最后,添加溢出的內容 ,您只是在請求IE11破壞您的布局。
也就是說,解決該問題的方法是在代碼中添加兩個規則:
.container { width: 100%; /* new */ table-layout: fixed; /* new */ display: table; max-width: 277px; height: 100px; background-color: yellow; } .inner { background-color: red; display: flex; height: 50px; }
<div class="container"> <div class="inner">77 777 777 77 7 7777 77 7 7 7 77 7 7 7 77 7 7 7 7 7 77 7 7 7 7 77 7 77 7 7 77 7 7 77 7 7 77 7 7 77 7 7 7 7 7</div> <div class="inner">111 11111 111111111111 111111111111 111111111 111111111111 11111111111 11111111111 11111111 1111111111 11111</div> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.