html - Responsive image, fixed ratio. Can't get code working -


sorry have been trying numerous tutorials on net try , make image responsive/scaling fixed aspect ratio, nothing working.

it's 900x400px image , want keep visible on smaller screens etc.

here's codepen link

<html> <head> <meta charset="utf-8"> <title></title> </head> <body>  <div id="aboutsec1"> <div class="parallaxbg"> <div class="parallaxcontainer"> <div class="parallaxcontent"> <h1>header</h1> "lorem ipsum dolor sit amet, consectetur adipisicing elit, sed eiusmod tempor incididunt ut labore et dolore magna aliqua. ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." </div> </div> </div> </div>  <section id="aboutsec2"> <div class="parallaxbg"></div> <div class="parallaxbg2"></div> </section>  </body> </html> 

css

html,body{     width:100%;     height:100%;   margin: 0;   padding: 0; }  /* basic parallax background */ .parallaxbg {     background-position: center center;     background-repeat: no-repeat;     background-attachment: fixed;     background-size: cover;     height: 100%;     width: 100%;     position: relative; }  /* basic parallax container */ .parallaxcontainer {     display: table;     table-layout: fixed;     width: 100%;     height: 100%;     overflow: hidden;     position: relative; }  /* basic parallax content */ .parallaxcontent {     max-width: 450px;     display: table-cell;     vertical-align: middle;     padding-left: 10%;     padding-right: 10%;     text-align: center; }  #aboutsec1{     height: 100%; }  /* page section 1 */ #aboutsec1 .parallaxbg {     background: none;     background-color: #eeeeee;     text-align: center; }  /* page section 2 */ #aboutsec2 { }  #aboutsec2 .parallaxbg2 {     background-color: #000000;     background-image: url('http://s16.postimg.org/k5xrwvp7p/900x400.png');     z-index: 1;     background-position: center center;    background-repeat: no-repeat;     background-attachment: fixed;     width: 100%;     background-size: cover;   padding-bottom: 44.444444444444%; /* 400px/900px */ } 

don't worry, figured out myself eventually. here's code fixed aspect ratio responsive background image if else needs it...

<div class="imagecontainer">     <div class="responsiveimage"></div> </div>  .imagecontainer {     margin: 0px auto;     max-width: 900px; \* 900px wide image *\ }  .responsiveimage {     background-image: url('');     background-position: center center;     background-repeat: no-repeat;     background-size: contain;     padding-bottom: 44.444444444444%; /* 400px/900px x 100 (for 900x400 image) */ } 

set padding bottom correct ratio using sum, means image keep same aspect ratio.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -