【问题标题】:Increasing the height of div dynamically if page width increases如果页面宽度增加,动态增加 div 的高度
【发布时间】:2022-01-30 17:08:15
【问题描述】:

在我的 CSS 中,我想:

  • div 永远不要低于高度(最小高度)
  • div 不得超过特定高度(最大高度)
  • 如果我增加页面宽度,我希望 div 高度动态增加(或者如果我减小页面宽度,则减少)。

类似:

div{
  min-height: 10vw;
  max-height: 30vw;
  height: calc(??);
}

这可以实现吗?

【问题讨论】:

  • 它按照您想要的方式工作。并且不需要高度

标签: css responsive-design frontend


【解决方案1】:

你不会用Js?如果您使用 js,则可以使用 window.innerWidth 并将其分配给元素。 例如:

let windowWidth = window.innerWidth;
document.getElementById("myDynamicHeight").style.height = `${windowWidth}px`; 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-02
    • 2011-11-26
    • 1970-01-01
    • 2021-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多