html - how to make div float center of viewport always using CSS -


the goal have div (willscape-holder in case) containing 2 images float in middle of viewport always. there way without having media queries adjusting margin top , bottom every type of screen? thank in advance.

body {    background: url(../images/willscape-bg.png);    background-repeat: no-repeat;    background-size: 100% 100%;    /* background-position: center top; */    background-attachment: fixed;  }    .container {    height: 100vh;  }    .willscape-holder {    width: 100%;    max-width: 350px;    margin: 0 auto;    padding: 0 20px;  }    #willscape-logo {    padding: 0 60px;    width: 100%;  }    #willscape-title {    width: 100%;    max-width: 500px;  }
<body>    <div class="container">      <div class="willscape-holder">        <a href="" target="_blank"><img class="img-responsive" id="willscape-logo" src="assets/images/willscape-logo.png" /></a>        <a href="" target="_blank"><img class="img-responsive" id="willscape-title" src="assets/images/willscape.png" /></a>      </div>    </div>  </body>

you may use display:table/table-cell; properties

https://www.w3.org/tr/css2/tables.html

17.2 css table model

the css table model based on html4 table model, in structure of table closely parallels visual layout of table. in model, table consists of optional caption , number of rows of cells. table model said "row primary" since authors specify rows, not columns, explicitly in document language. columns derived once rows have been specified -- first cell of each row belongs first column, second second column, etc.). rows , columns may grouped structurally , grouping reflected in presentation (e.g., border may drawn around group of rows).

thus, table model consists of tables, captions, rows, row groups (including header groups , footer groups), columns, column groups, , cells.

/* update*/  html {  height:100%;/* equals min-height */  width:100%;  table-layout:fixed ; /*if fixed,  width width not min-width */  display:table;  }  body {  display:table-cell;  vertical-align:middle;  /* end update */    background: url(../images/willscape-bg.png);    background-repeat: no-repeat;    background-size: 100% 100%;    /* background-position: center top; */    background-attachment: fixed;  }    .container {   /* height: 100vh;*/  }    .willscape-holder {    width: 100%;    max-width: 350px;    margin: 0 auto;    padding: 0 20px;  }    #willscape-logo {    padding: 0 60px;    width: 100%;  }    #willscape-title {    width: 100%;    max-width: 500px;  }
<body>    <div class="container">      <div class="willscape-holder">        <a href="" target="_blank"><img class="img-responsive" id="willscape-logo" src="assets/images/willscape-logo.png" /></a>        <a href="" target="_blank"><img class="img-responsive" id="willscape-title" src="assets/images/willscape.png" /></a>      </div>    </div>  </body>


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -