【问题标题】:How can i resize the Div dynamically according to the containing image Size如何根据包含的图像大小动态调整 Div 大小
【发布时间】:2013-11-14 16:37:59
【问题描述】:

我在这里进退两难。 我正在研究一个模态库,并将图像 css 设置为根据浏览器窗口调整大小。现在我需要一个 div 围绕它,以便我可以在其上放置一些文本或按钮。 图像的大小调整得很好,但我无法根据图像大小设置包含的 div。 我尝试使用红色边框来包含 div 但它失败了。 请帮忙。 这是一个小提琴,可以帮助您了解我想要做什么。 谢谢。

这是 CSS 代码

    #imagePlaceholderContainer {
        border: 3px solid Red;

    }
     #imagePlaceholder {
        margin: auto;
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
        z-index: 999;
        max-height: 80%;

    }

这里是完整的代码--> FIDDLE

【问题讨论】:

标签: css


【解决方案1】:

去掉position: fixed,否则必须在父#imagePlaceholderContainer上指定widthheight

【讨论】:

  • 摆脱位置:固定不会使边框红色 div 围绕 iage 进行修复。它只是伸展。
  • 当然可以 - 它只是拉伸,因为父级是 display: block; 没有设置宽度。除非另有说明,否则所有 <div> 都会填充其父宽度。
  • 你能修好小提琴吗?!
  • 不!不是我想要的。
猜你喜欢
  • 1970-01-01
  • 2019-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-07-04
  • 2011-12-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多