CSS max-width:-webkit-fit-content 即 8 等价物?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17438597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:23:29  来源:igfitidea点击:

max-width:-webkit-fit-content ie 8 equivalent?

cssinternet-explorerinternet-explorer-8

提问by HelloWorld

Are there any hacks for max-width:-webkit-fit-content;for ie 8?

max-width:-webkit-fit-content;ie 8有什么技巧吗?

Trying to get a child div to not take up the whole width of the parent and this works well with ff, chrome and safari; hoping there's some hack to get it to work with ie 8 as well.

试图让子 div 不占用父级的整个宽度,这适用于 ff、chrome 和 safari;希望有一些技巧可以让它与 ie 8 一起工作。

Fiddle showing the behavior: http://jsfiddle.net/XtZq9/Code for the behavior I want in ie8:

小提琴显示行为:http: //jsfiddle.net/XtZq9/我想要在 ie8 中的行为代码:

#wrap {
    background-color: aqua;
    width:300px;
    height: 50px;
    padding-top: 1px;
}

.textbox {
    background-color: yellow; 
    max-width: intrinsic;
    max-width:-webkit-fit-content;
    max-width:  -moz-max-content;
    margin-top: 2px;
}

<div id="wrap">
     <div class="textbox">
        Here is some text
    </div>  
    <div class="textbox">
        Here is other, longer, text
    </div>  
</div>  

采纳答案by Christoph

The closest I can think of is floating your elements. Not exactly alike, but probably sufficiently alike;) You need to set extra margin though, but this should be no problem with a conditional stylesheet.

我能想到的最接近的是浮动你的元素。不完全相同,但可能足够相似;) 虽然您需要设置额外的边距,但这对于条件样式表应该没有问题。

.textbox {
    background-color: yellow;
    float:left;
    clear:left;
}

Your modified fiddle

你修改过的小提琴

回答by Veverke

From demosthenes.info, I learned I can simply use

demosthenes.info,我了解到我可以简单地使用

display: table;

instead of

代替

width: fit-content;

Check the link however about problems with whitespaces. It does not apply to my case, and simply replacing width: fit-contentwith display: tablesolved my problem quite easily.

但是,请检查有关空格问题的链接。它不适用于我的情况,只需将width: fit-content替换为display: table就很容易解决了我的问题。

回答by Nacho Perassi

It might depends on the situation:

这可能取决于情况:

I had a block-level element with width: fit-content;. As this doesn't work on IE, the element was taking the full available width (as expected).

我有一个块级元素,宽度为:fit-content; . 由于这在 IE 上不起作用,因此该元素采用了完整的可用宽度(如预期)。

But I wanted it to just adjust its size to its content.

但我希望它只是根据其内容调整其大小。

Finally, i fixed it with:

最后,我修复了它:

display: inline-flex;