javascript - Height 100% not working for nested div -
i tried make child div take height 100% it's not working, i'd know why not working: give html, body height: 100% .hero height 100% , .hero-image must 100%:
html, body{ height:100%; } .hero{ width:100%; height:100%; border:1px solid #0094ff; .hero-image{ width:100%; height:100%; background-image:url('../images/1.jpg'); background-size:cover; } }
<section class="hero"> <div class="container-fluid"> <div class="row"> <div class="col-lg-6"> <div class="hero-image"> hello </div> </div> <div class="col-lg-6"> <div class="hero-content"> <h1>hey, mike ross</h1> <p> creative art director san francisco. husband, photographer, surfer , tech fanatic. </p> </div> <div class="skills"> </div> </div> </div> </div> </section>
height 100% elusive issue, , creates more problems solves. however, answer question:
basically, every container between html
element , element want 100% must have height: 100%;
on it.
so, in case, means following css must added:
/* these styles of containers 100% height */ /* address sub-elements of .hero element prevent issues other pages / code */ .hero .container-fluid, .hero .row, .hero [class*="col-"] { height: 100%; }
below code, built snippet, can see work. note i've additionally added col-sm-6
classes col-lg-6
elements can see work in narrower window. (note: click "expand snippet" link in order wide enough window see working).
html, body { height: 100%; } .hero { width: 100%; height: 100%; border: 1px solid #0094ff; } .hero-image { width: 100%; height: 100%; background-image: url('http://via.placeholder.com/500x100'); background-size: cover; } /* these styles of containers 100% height */ .hero .container-fluid, .hero .row, .hero [class*="col-"] { height: 100%; }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <section class="hero"> <div class="container-fluid"> <div class="row"> <div class="col-lg-6 col-sm-6"> <div class="hero-image"> hello </div> </div> <div class="col-lg-6 col-sm-6"> <div class="hero-content"> <h1>hey, mike ross</h1> <p> creative art director san francisco. husband, photographer, surfer , tech fanatic. </p> </div> <div class="skills"> </div> </div> </div> </div> </section>
Comments
Post a Comment