我有一个叠加图像需要垂直和水平响应才能在桌面和移动设备上工作。垂直和水平响应图像
编辑:通过垂直响应,我的意思是它需要保持在窗口内,而不是在屏幕底部以下溢出。
图片顶部有一个元素需要留在同一个地方,图片必须保留其长宽比。
我宁愿用纯CSS做这件事,但可以使用JS来实现浏览器兼容性或更简单的解决方案。
http://codepen.io/brooksroche/pen/mEgJmd?editors=1100
<div class="container">
<div class="img-container">
<img src="http://placehold.it/300X200">
<div class="example"></div>
</div>
</div>
.container {
position: fixed;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
.img-container {
position: relative;
margin: 0 auto;
border: 1px solid red;
width: 300px;
max-width: 100%;
}
.img-container img {
display: block;
max-width: 100%;
max-height: 100%;
}
.example {
position: absolute;
border: 1px solid blue;
top: 40%;
left: 30%;
width: 38%;
height: 20%;
}
你有没有这样的事情“调整大小,但保持宽高比”? http://stackoverflow.com/questions/12991351/css-force-image-resize-and-keep-aspect-ratio这是问题,你有吗? –