I have a div I use as a container and an image I use as a "background" (not literally, I was told I couldn't do this with background attribute) and then a content div:

我有一个div我用作容器和一个图像我用作“背景”(不是字面意思,我被告知我不能用背景属性做这个)然后一个内容div:

CSS

#container {
  display:table;
  width: 100%;
  min-width:100%;
}

.img1 {
  //DON'T KNOW WHAT TO PUT HERE;
}

#content {
  //not important;
}

HTML

<div id="container">
    <img class="img1" src="img.png"/>
    <div id="content"> Content </div>
</div>

I need the container div to be 100% screen width, and so the contained image, while both of them must have the image's resulting height (after the resizing from taking 100% screen width) (no stretching). Any way to do that? I tried a lot of min-height and width combination but nothing worked so far. I prefer CSS and HTML only solutions, if possible.

我需要容器div为100%的屏幕宽度,因此包含的图像,而它们都必须具有图像的最终高度(在调整大小后取100%的屏幕宽度)(无拉伸)。有办法吗?我尝试了很多最小高度和宽度组合但到目前为止没有任何工作。如果可能的话,我更喜欢CSS和HTML解决方案。

2 个解决方案

#1


0

Not exactly sure what you mean, but how does this look: https://jsfiddle.net/b76fjtcv/

不完全确定你的意思,但这看起来如何:https://jsfiddle.net/b76fjtcv/

basically it's

.img1 {width: 100%;}

This updated version of the fiddle also adds a max width to the img so it doesn't get too fuzzy. Just set the max-width of the .img1 to the image's full width.

这个小提琴的更新版本也为img添加了最大宽度,因此它不会太模糊。只需将.img1的最大宽度设置为图像的全宽。

更多相关文章

  1. javascript自适应宽度的瀑布流
  2. 如何将图像(PNG)转换为2D数组(二进制图像)?
  3. 使用CSS,HTML和Javascript在随机图像的页面上进行图像大小调整
  4. 在图像映射中的背景图像
  5. 动画在画布中移动图像
  6. 如何修复一个页面网站的容器/正文宽度(html,css和js)
  7. JS计算任意字符串宽度
  8. Nivoslider(在动态ajax内容中)不会在第一次加载时加载图像
  9. 即使通过一系列图像预先加载也表现不佳

随机推荐

  1. 与symfony一起使用ajax时出现500内部服务
  2. jquery解析php通过ajax传过来的json二维
  3. java前端实时绘制不连续时间点多系列折线
  4. 从ajax查询返回的数组看起来还可以,但是它
  5. jQuery datepicker在IE8中遇到麻烦?
  6. 基于JQuery+JSP的无数据库无刷新多人在线
  7. Access-Control-Allow-Origin不允许使用O
  8. 自定义滚动条插件
  9. 如何为每个JQuery UI滑块句柄使用不同的
  10. 无法通过jquery Ajax在laravel 5中发布