Html 如何配置模式窗口以适合所包含图像的实际大小?
我正在使用Bootstrap 4.2来显示一个弹出窗口(模式),其中的图像在宽度和高度上都是真实大小(100%),只要浏览器窗口的大小允许,如果不允许,也就是说,如果图像大于窗口的大小,那么它将自动缩小。我试过使用以下代码,但是图像在模式的宽度上放大了(+100%),尽管我将其配置为max width:100%Html 如何配置模式窗口以适合所包含图像的实际大小?,html,css,bootstrap-4,Html,Css,Bootstrap 4,我正在使用Bootstrap 4.2来显示一个弹出窗口(模式),其中的图像在宽度和高度上都是真实大小(100%),只要浏览器窗口的大小允许,如果不允许,也就是说,如果图像大于窗口的大小,那么它将自动缩小。我试过使用以下代码,但是图像在模式的宽度上放大了(+100%),尽管我将其配置为max width:100% <!DOCTYPE html> <html lang="es"> <head> <meta charset="utf8">
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Imagen 100%</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
</head>
<body>
<style>
.img-100{
max-width: 100%;
max-height: 100%;
}
</style>
<a href="#modalArticulo" role="button" class="btn btn-primary" data-toggle="modal">Launch modal</a>
<div id="modalArticulo" class="modal fade " tabindex="-1" role="dialog">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<img src="../images/Imagen360x360.jpg" class="img-100">
<!-- <img src="../images/Imagen1200x1200.jpg" class="img-100"> -->
</div>
</div>
</div>
</body>
</html>
Imagen 100%
.img-100{
最大宽度:100%;
最大高度:100%;
}
图像将动态加载,因此默认情况下我无法知道图像的大小。将边距设置为“自动”将防止图像拉伸以填充模式div的宽度和高度。无需设置图像的最大宽度或最大高度
.modal-image {
margin: auto
}
.modal-content {
width: unset;
margin: auto;
}
此外,添加这个类可以使模式适合图片并在屏幕上居中显示。如果没有它,模式将显示图像周围的边框
.modal-image {
margin: auto
}
.modal-content {
width: unset;
margin: auto;
}
将边距设置为“自动”将防止图像拉伸以填充模式div的宽度和高度。无需设置图像的最大宽度或最大高度
.modal-image {
margin: auto
}
.modal-content {
width: unset;
margin: auto;
}
此外,添加这个类可以使模式适合图片并在屏幕上居中显示。如果没有它,模式将显示图像周围的边框
.modal-image {
margin: auto
}
.modal-content {
width: unset;
margin: auto;
}
这不起作用,它没有响应能力。尝试使用比窗口大的图像,例如1200x1200。这不起作用,它没有响应能力。尝试使用比窗口大的图像,例如1200x1200。