html - Center a div horizontally and vertically even on resize -


i saw asked few times of answers messed height.

    #transbox {              position: fixed;             top: 150px;             right: 320px;             width: 600px;             height: 210px;             background-color: #fff;             border: 1px solid #000;             opacity: 0.7;             filter: alpha(opacity=60);              }  <div id="transbox">  <div id="title">navigation</div>       <div id="navigation">         <table style="width:100%">             <tr>                 <td><a href="/">link</a></td>                 <td><a href="/">link</a></td>                 <td><a href="/">link</a></td>             </tr>              <tr>                 <td><a href="/">link</a></td>                 <td><a href="/">link</a></td>                 <td><a href="/">link</a></td>             </tr>              <tr>                 <td><a href="/">link</a></td>                 <td><a href="/">link</a></td>                 <td><a href="/">link</a></td>             </tr>         </table>     </div>  </div>     

that div , it's css , want make height same content inside if have specific height (like @ moment) limit answers have seen centering horizontally , vertically on page resize rely on specific height

thanks

one of options use flexbox. there's snippet below -- can see works clicking "full page" when running it:

html, body { height: 100%; margin: 0; }  #container {    height: 100%;    display: flex;    align-items: center;    justify-content: center;  }  #transbox {    position: relative;    width: 600px;    background-color: #fff;    border: 1px solid #000;  }
<div id="container">    <div id="transbox">      <div id="title">navigation</div>      <div id="navigation">        <table style="width:100%">          <tr>            <td><a href="/">link</a></td>            <td><a href="/">link</a></td>            <td><a href="/">link</a></td>          </tr>          <tr>            <td><a href="/">link</a></td>            <td><a href="/">link</a></td>            <td><a href="/">link</a></td>          </tr>          <tr>            <td><a href="/">link</a></td>            <td><a href="/">link</a></td>            <td><a href="/">link</a></td>          </tr>        </table>      </div>    </div>  </div>

for option, you'll need have container (it can height, demo made full height). then, on container, apply display: flex , align content center horizontally , vertically using align-items , justify-content.

keep in mind child, or item, in flexbox .transbox element, aligned accordingly.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -