[英]css image scaling with margin or padding
I have a image (or 2) which I need to scale based on the size of the window. 我有一幅图像(或2张),我需要根据窗口的大小进行缩放。 It needs to have a minimum margin or padding.
它需要具有最小的边距或填充。
Is this possible in CSS / Javascript? CSS / Javascript有可能吗?
Ok here goes, don't shoot me. 好了,别开枪 I've tried with CSS so far and the closest I got is with jQuery and a table and some CSS:
到目前为止,我已经尝试过使用CSS,而最接近的是jQuery和一个表格以及一些CSS:
HTML: HTML:
<div id="myModal" class="modal">
<span class="close cursor" onclick="closeModal()">×</span>
<table>
<tbody>
<tr>
<td id="mBor1" style="min-width: 51.5px"></td>
<td id="mMain" style="table-layout:fixed">
<div class="mySlides">
<img id="slide1" src="img/SlideTest.png" class="transparent" >
</div>
</td>
<td id="mBor2" style="min-width: 51.5px"></></td>
</tr>
<tr><td style="min-height: 73px"></td></tr>
</tbody>
</table>
</div>
Javascript function: JavaScript函数:
function Adjust() {
modLen = $('#myModal').width();
$('#mBor1').width(modLen * 0.038);
$('#mBor2').width(modLen * 0.038);
$('#mMain').width(modLen - ($('#mBor1').width() * 2));
$('#slide1').width(modLen - ($('#mBor1').width() * 2));
}
CSS: CSS:
.modal {
display: none;
width: 100%;
height: 100%;
border: none;
position:absolute;
margin: 0;
padding: 0;
overflow: auto;
z-index: 20;
background-color: rgba(0,0,0,0) !important;
}
/* Modal Content */
.modal-content {
display: flex;
position: relative;
background-color: rgba(0,0,0,0);
margin: auto;
padding: 0;
width: 100%;
/* max-width: 1200px; */
}
table {
width:100%;
border-collapse:collapse;
table-layout:fixed;
}
#slide1
{
position: absolute;
}
I think this is what you are looking for: 我认为这是您要寻找的:
*{ box-sizing: border-box; } body{ width:100%; } div{ position: absolute; height: 100%; width: 100%; padding: 0 51.5px 73px; text-align: center; } img{ max-width:100%; max-height: 100%; height:auto; }
<body> <div> <img src="https://i.stack.imgur.com/w0hW9.png"> </div> </body>
if you have a big enough image, you can simply set 如果您有足够大的图像,只需设置
max-height:100%;
max-width:100%;
on it, in a container with 在上面,放在一个装有
margin:0 52px 73px 52px;
for example, however, if the image is too small , it won't take all the place 例如,但是,如果图像太小,则不会占据所有位置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.