To ensure your image is responsive, you can utilize the img-fluid
class from the bootstrap css framework. Simply eliminate the html attributes
height="300" width="400"
from your image markup. Your comprehensive inquiry indicates that this solution aligns with your desired UI outcome.
Your updated code snippet could resemble the following:
<div class="row">
<div class="col-md-6">
<div class="border">
<!-- Remove fixed dimensions and add img-fluid class -->
<img class="img-fluid rounded" src="~/foo/bar.png">
<p>Lorem ipsum...</p>
</div>
</div>
</div>
Description: Bootstrap's .img-fluid
ensures image responsiveness by applying
max-width: 100%; and height: auto;
to scale with the parent element.
Refer to the official bootstrap documentation for further details:
- 4.6.x (currently used by ASP.NET Core 3.1)
- 5.0.x (will be default soon)
PS: I recommend transferring all style declarations from inline-markup to your css file for improved coding practices. Bootstrap offers essential layout and design utilities to streamline your work (refer to my answer).