简体   繁体   中英

make image height fit inside the screen

I have a image inside a bootstrap code

<header>
My Header
</header>

<div class="container">

<div class="col-md-8">
<div class="col-image">
<img src="my-image.jpg" >
<div>
</div><!--col-md-8-->

<div>
comments
</div>


<div class="col-md-4">
my sidebar
</div><!--col-md-4-->

</div><!--container-->

<footer>
my footer
</footer>

I want image height to be inside screen of any size. Responsive height

I try adding height:auto; max-height:100vh; height:auto; max-height:100vh; but didnt work at all. Any help is appropriated.

The image parents should be a height defined. So, you can set max-height, or height. Search about heitgh in percent ;)

PS.: See in full page

 .col-image{ height: 100vh; border: 1px solid red; } img{ float:left; max-height: 100%; height: 100% } 
 <header> My Header </header> <div class="container"> <div class="col-md-8"> <div class="col-image"> <img src="http://papodeturista.com/wp-content/uploads/2016/02/arvore.jpg" > <div> </div><!--col-md-8--> <div> comments </div> <div class="col-md-4"> my sidebar </div><!--col-md-4--> </div><!--container--> <footer> my footer </footer> 

Add the class img-responsive.

<img src="my-image.jpg" class="img-responsive" />

More information here: Bootstrap Images

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM