-1
I set a height for my div, with 300px of height and width, but the image is leaving outside my div, but when I use the bootstrap on a card the image is totally right inside the div why it happens ?
Example
<!DOCTYPE html>
<html>
<head>
<title>Teste imagem</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<style type="text/css">
.conteudo{
width: 300px;
height: 300px;
}
</style>
</head>
<body>
<div>
<img style="width: 100%;" src="https://tecnoblog.net/wp-content/uploads/2019/05/tv-4k-tcl-c6-c6us-6.jpg">
</div>
<div class="card" style="width: 18rem;">
<img src="https://tecnoblog.net/wp-content/uploads/2019/05/tv-4k-tcl-c6-c6us-6.jpg" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
</body>
Because the image is being formatted to the same size as the
div
, manually just addheight
andwidth
on the tag<img>
, in your caseheight = 300px
– Pedro Roweder
One way to solve this is to place the dimensions directly on the image tag:
<img width="300" height:"300" src="https://tecnoblog.net/wp-content/uploads/2019/05/tv-4k-tcl-c6-c6us-6.jpg">
– Rafael Passos
@Rafaelpassos if you do this will break the proportionality of the image because it is not square.
– Sam
@Pedroroweder Same problem as above comment.
– Sam