html - background-image css does not show in img tag -
the responsive image in bootstrap html not show:
<div class="container-fluid"> <div class="row"> <div class="col-sm-12"> <img class="myimg img-responsive"/> </div> </div> </div>
css
.myimg { background-image: url("http://images.wikia.com/worldlanguages/images/6/63/wikipedia-logo.png"); display:block; height:100%; width:100%; }
<img src="...">
work, need define image in css.
this similar thread suggests using <div>
, removing quotes in url()
, did not help.
why not show?
you need set height of parents, , need background-size: cover
(demo)
html, body { height: 100%; } .container { height: 100%; } .row, .col-sm-12 { height: 100%; } .myimg { background-image: url("//lorempixel.com/200/200"); background-size: cover; display: block; height:100%; width:100%; } .myimg2 { background-image: url("//lorempixel.com/200/200"); background-size: cover; display: block; height:100%; width:100%; } .myimg3 { background-image: url("//lorempixel.com/200/200"); background-size: cover; display: block; height:100%; width:100%; }
if responsively change background image, can so.
(demo)
html, body { height: 100%; } .container { height: 100%; } .row, .col-sm-12 { height: 100%; } .myimg, .myimg2, .myimg3 { background-size: cover; display: block; height:100%; width:100%; } @media (max-width: 500px) { .myimg { background-image: url("//lorempixel.com/500/500/cats"); } .myimg2 { background-image: url("//lorempixel.com/500/500/business"); } .myimg3 { background-image: url("//lorempixel.com/500/500/transportation"); } } @media (max-width: 750px) { .myimg, .myimg2, .myimg3 { .myimg { background-image: url("//lorempixel.com/750/750/cats"); } .myimg2 { background-image: url("//lorempixel.com/750/750/business"); } .myimg3 { background-image: url("//lorempixel.com/750/750/transportation"); } } } @media (max-width: 1000px) { .myimg { background-image: url("//lorempixel.com/1000/1000/cats"); } .myimg2 { background-image: url("//lorempixel.com/1000/1000/business"); } .myimg3 { background-image: url("//lorempixel.com/1000/1000/transportation"); } }
Comments
Post a Comment