【问题标题】:-moz-max-content does not work for mozilla firefox-moz-max-content 不适用于 mozilla firefox
【发布时间】:2019-12-28 11:35:26
【问题描述】:

如何让 div 适合 Mozilla Firefox 中的内容?

当新元素添加到 div 中时,使用 -moz-max-content 使 div 适合内容不会影响动态大小。

我尝试了以下方法:

  1. 它只作用于高度:450px
.login-container{
   height: auto;
   max-height: 450px;
}
  1. Div 获得完整的身体高度
.login-container{
   max-height: fit-content;
   height: -moz-max-content;
}

(1) 给出了预期的结果,但自动将高度设置为最大高度。

(2) div 被拉伸到页面底部。

基本上,我想要一个基于内部元素的动态大小的 div 容器。

【问题讨论】:

  • 你到底想问什么?
  • 对不起,我将在此评论后修改问题。我的问题是,{height: fit-content} 与 Google Chrome 完美配合。但是在 Mozilla 中,他们使用 {height: -moz-max-content};我也试过 {height: -moz-fit-content}: 但这些都没有真正起作用。如何让 div 适合 Mozilla 的内容?

标签: html css mozilla


【解决方案1】:

-moz-*-content 不适用于height

怎么知道

$('textarea').on('keyup',function(){
  var text = $( this ).val().replace(/\n/g, '<br />');
  text.replace('&#10;','<br/>'); 
  $('div').html(text);
});
div{
  background-color:#00ffff;
  width: 500px;
  height: 50px;
}
div.yourfit{
  background-color:#ff00ff;
  max-width:-moz-max-content;
  max-height:-moz-max-content;
}
div.myfit{
  background-color:#ffff00;
  max-width:-moz-max-content;
  min-height: 50px;
  height:auto;
}

/*Dont care*/
textarea{
  position: fixed;
  width: 90%;
  bottom: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<textarea></textarea>

<div>
  Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>

<div class="myfit">
  Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>
<div class="yourfit">
  Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>

对于使用内容的动态高度...只使用这个

  min-height: 50px;
  height:auto;

【讨论】:

  • 最大宽度:-moz-max-content; -> 宽度有效。最大高度:-moz-最大内容; -> 高度不
  • -moz-max-content 不能 USED with height
猜你喜欢
  • 2012-08-09
  • 2012-12-12
  • 1970-01-01
  • 2012-08-01
  • 2015-11-18
  • 2016-12-30
  • 1970-01-01
  • 2014-05-20
  • 1970-01-01
相关资源
最近更新 更多