[英]How to set adaptive background to the image?
Before(On my screen resolution (1024px))
之前(在我的屏幕分辨率(1024像素)上)
After (On the other resulution - for example screen width:1500px)
之后(在另一个重新分辨率上-例如屏幕宽度:1500px)
#quotes_div img{ width: 100vh; margin-left: 3%; margin-top: 3%; } #quotes_div{ position: relative; } #quotes_div #img{ width: 82.5%; height: 38.5vh; background: red; }
<div id="quotes_div"> <h3>My favorite quotes to which I adhere</h3> <i class="fa fa-quote-left fa-2x fa-inverse" aria-hidden="true"></i> <i class="fa fa-quote-right fa-2x fa-inverse" aria-hidden="true"></i> <p>Even an impossible dream can lead to action</p> <div id="img"> <img src="assets/fielding.jpg" alt="Field"> </div> </div>
I need to the picture Nr.1 and "border"(background) will have same resolution. 我需要图片Nr.1和“边框”(背景)具有相同的分辨率。 + I am sorry (I am not at formating text on stackoverflow)
+很抱歉(我不打算在stackoverflow上格式化文本)
To make your image responsive, and stay within the red border, don't force a specific height, just specify container and image as 100% and add padding around the image to show the red background. 要使图像具有响应性并保持在红色边框内,请勿强行指定特定高度,只需将容器和图像指定为100%,并在图像周围添加填充以显示红色背景。
See this example it now works, add or remove padding as you see fit: 请参阅以下示例,该示例现在可以正常工作,并根据需要添加或删除填充:
#quotes_div img{ width: 100%; } #quotes_div{ position: relative; } #quotes_div #img{ width: 100%; background: red; padding: 1em; }
<div id="quotes_div"> <h3>My favorite quotes to which I adhere</h3> <i class="fa fa-quote-left fa-2x fa-inverse" aria-hidden="true"></i> <i class="fa fa-quote-right fa-2x fa-inverse" aria-hidden="true"></i> <p>Even an impossible dream can lead to action</p> <div id="img"> <img src="http://placehold.it/1000x350" alt="Field"> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.