2
Hello,
I’m starting my learning with dimensions and scales in Bootstrap. I started making a container
occupy the entire screen, and distributes 3 divs
to occupy the container independent of its contents. A div
top occupies 10%, to div
occupies middle 80%, and the div
bottom occupies 10%; completing 100%.
I decided to put a <img>
in div
of the middle, and I got the following problem: depending on the size of the image, it exceeds the limits of the div
.
I tried to use max-width inherit
and other properties to make it, if the image is larger than the div
, it will not exceed that limit, but I did not succeed. I would like some help on that.
HEAD:
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
<style type="text/css">
html {
height: 100%;
}
body, .container-fluid {
height: 100%;
}
</style>
<title>Dimensões e Escalas</title>
BODY:
<body>
<div class="container-fluid">
<div class="row" style="border: 5px solid red; height: 10%;">
<div class="col-12 h-50">Teste 10%</div>
</div>
<div class="row" style="border: 5px solid black; height: 80%">
<div class="col-12">
<img id="fotoExpandida" class="img-fluid rounded" src="http://ap.imagensbrasil.org/images/imagens-lobos.jpg" style="max-width: inherit; max-height: inherit;">
</div>
</div>
<div class="row" style="border: 5px solid blue; height: 10%;">
<div class="col-12">Teste 10%</div>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<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.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js" integrity="sha384-o+RDsa0aLu++PJvFqy8fFScvbHFLtbvScb8AjopnFD+iEQ7wo/CG0xlczd+2O/em" crossorigin="anonymous"></script>
Hello Tony, try using the
max-width:100%
instead ofinherit
. your code - jsfiddle– Icaro Martins
I have tried friend. The result is the same, the image is at its maximum size. However, if I set to 90%, 80%, etc., the image will decrease in size. But if I assign percentage, depending on the screen size, it will exceed the div limit. That’s why I have to somehow make the image responsive, but not allow it to exceed the limit of its relative (div).
– Tony Starkus