简体   繁体   English

内联块不会在Firefox中调整为儿童大小

[英]Inline-block doesn't resize to children in Firefox

I am trying to create a custom, responsive image-map, in which the "area"-elements, represented by "a" tags, are styled with percentages. 我正在尝试创建一个自定义的响应式图像贴图,其中以百分比表示由“ a”标签表示的“区域”元素。 While the following code works in Chrome and Opera, I simply can't get the desired result with Firefox: 虽然以下代码可在Chrome和Opera中运行,但使用Firefox却无法获得理想的结果:

In Chrome and Opera, it behaves like it should (as I understand) by sizing the outer div with the class "map-wrapper" to the image's size. 在Chrome和Opera中,通过将类“ map-wrapper”的外部div调整为图像的大小,它的行为就像我应该理解的那样。 Firefox though will always make "map-wrapper" full width, even though it is clearly styled to behave like "inline-block". 尽管Firefox的样式显然类似于“内联块”,但Firefox始终会使其全宽度。

FIDDLE: Code example FIDDLE: 代码示例

HTML: HTML:

    <div class="map-container">
  <div class="map-wrapper">
    <img src="hhttps://apod.nasa.gov/apod/image/1611/ChicagoClouds_Hersch_3600.jpg" usemap="map">
    <a class="img-map-event" href="#"></a>
    <a class="img-map-event" href="#"></a>
    <a class="img-map-event" href="#"></a>
    <a class="img-map-event" href="#"></a>
    <a class="img-map-event" href="#"></a>
  </div>
</div>

CSS: CSS:

img{
  height: 100%;
}
.map-container{
  text-align: center;
  box-sizing: border-box;
}
.map-wrapper{
  display: inline-block;
  position: relative;
  max-height: 100%;
  text-align: center;
  border: 1px solid #000;
}

The desired result is that the "map-wrapper" is always perfectly surounding it's child and addapts the width and height of it. 理想的结果是,“地图包装器”始终完美环绕其子级,并增加其宽度和高度。

I'm realy looking forward in solving this issue, so thank you for reading. 我非常期待解决这个问题,非常感谢您的阅读。

The problem was that Chrome's 100% height on images works differently than Firefox's 100%. 问题是Chrome的图像高度100%与Firefox的100%高度不同。 Firefox will definitly scale to 100% of the images size while Chrome will scale to the available space. Firefox将最终缩放到图像大小的100%,而Chrome将缩放到可用空间。

Adding the style "height: calc(100vh - Y px);" 添加样式“高度:calc(100vh-Y px);” to the image will always scale to the available space on the webpage, leading to desired result. 图像将始终缩放到网页上的可用空间,从而获得所需的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM