html - 我怎样才能使 div *不* 扩展以填充它的父级?

标签 html css layout

我有一个包裹着图像的 div,如下所示:

<div class="containing-div">
      <div class="image-wrapper">
           <img src="image.jpg">
      </div>
      <div class="unrelated-stuff">
           Blah blah blah.
      </div>
</div>

现在,我期望 image-wrapper获取图像的大小,仅此而已。但事实并非如此;它会填充到 containing-div 的高度. (在此处查看实际页面:http://holyworlds.org/new_hw/wallpapers.php)

我的 CSS 是:

.image-wrapper{
  float: left;
  box-shadow: inset 0px 4px 10px black;
  background-image: url('image.jpg');
}

.image-wrapper img{
  visibility: hidden;
}
.unrelated-stuff{
  float: left;
}

现在,如果我没有声明 Doctype,它就可以正常工作。但如果我这样做,我尝试过的一切都会失败。

我怎样才能制作image-wrapper仍然使用 <!doctype html> 时图像的大小?

最佳答案

你试过吗:

.image-wrapper {
  display: inline;
}

或者:

.image-wrapper {
  display: inline-block;
}

或者:

.image-wrapper {
  float: left;
}

关于html - 我怎样才能使 div *不* 扩展以填充它的父级?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6238676/

相关文章:

html - 使用推/拉和 col-md-12 在 Bootstrap 4 中进行列排序

layout - SWT更新/重绘/布局问题

java - 在拖放中更新阴影 View

html - 在 div 下 float 文本

css - 如何使小圆圈的边框平滑?

css - 为内容移出容器的菜单设置垂直背景

ruby-on-rails - Rails yield 和 content_for 部分

html - DOCTYPE 声明删除了我的背景图片

css - 输入占位符的 HTML5 图像图标

php - 更好的 PHP 和 Json