[英]How to keep 100% height + aspect ratio on full width background consisting of 8 different “prism” images
I have 8 's / background images - each image has the exact same size and is positioned the same. 我有8张/背景图片-每张图片的尺寸都完全相同,并且位置相同。
Each is defined with background-size: cover
and background: top center fixed
. 每一个都用
background-size: cover
和background: top center fixed
。
Fiddle here: http://jsfiddle.net/p19xu1er/ 在这里提琴: http : //jsfiddle.net/p19xu1er/
My issue is that I want to show all of the prism image and still keep aspect ratio in a full width solution, and currently I experience on a bigger screen/resolution that especially prism marked with "4" will have it's bottom "joint"/"angle" line appear off-screen. 我的问题是,我想显示所有棱镜图像,并仍将宽高比保持在全宽解决方案中,目前,我在较大的屏幕/分辨率上体验到,尤其是标有“ 4”的棱镜将具有其底部的“联合” / “角度”线出现在屏幕外。
If you resize the fiddle browser width to something high you can see this and if you re-size to something low you can see it appear. 如果将小提琴浏览器的宽度调整为较高的大小,则可以看到,如果将其调整为较低的大小,则可以看到它。
I know this is because it's defined as background: top center fixed
- however defining it to "bottom", will mis-align it. 我知道这是因为它被定义为
background: top center fixed
-但是将其定义为“底部”,将导致其未对齐。
Any suggestions on what I could do? 有什么建议我可以做什么? I don't mind taking use of JS/Jquery if there's no other way.
如果没有其他方法,我不介意使用JS / Jquery。
If you don't mind the shape of the prisms being skewed when the screen resizes, you could do something like this instead: 如果您不介意在调整屏幕大小时偏斜的棱镜形状,则可以执行以下操作:
CSS: CSS:
div {
position: absolute;
top: 0;
left: 0;
}
div img {
width: 100%;
height: 100%
}
HTML: HTML:
<div id="p1"><img src="http://i.imgur.com/Q8G7qJl.png"></div>
<div id="p2"><img src="http://i.imgur.com/KWi4kKy.png"></div>
<div id="p3"><img src="http://i.imgur.com/8bEneh3.png"></div>
<div id="p4"><img src="http://i.imgur.com/Dj47i8e.png"></div>
<div id="p5"><img src="http://i.imgur.com/BqEIfYC.png"></div>
<div id="p6"><img src="http://i.imgur.com/572QfZm.png"></div>
<div id="p7"><img src="http://i.imgur.com/ZxEhjkO.png"></div>
<div id="p8"><img src="http://i.imgur.com/vYvYnjq.png"></div>
Cover is used when you're trying to completely fill in the background. 当您尝试完全填充背景时,请使用Cover。 It naturally hides excess.
它自然会掩盖多余的东西。 I tried using contain and that kept the proportions, but it didn't completely fill the screen's height.
我尝试使用contains并保留了比例,但是它没有完全填满屏幕的高度。 It would be hard to come up with a javascript solution because it's difficult to make changes based on the height/width of a background image.
很难提出一个javascript解决方案,因为很难根据背景图片的高度/宽度进行更改。
I really hope this helps! 我真的希望这会有所帮助! You have a bit of a tricky situation on your hands.
您手上的情况有些棘手。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.