Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72443

How to vertically center an image within a fixed div

$
0
0

I'm trying to vertically center this image within the fixed position divs, but I cannot seem to get it to work. I have read other questions and the answers I've found don't work with a fixed position like I need. What am I missing? Thanks!

JSFiddle: https://jsfiddle.net/fudt38j4/

<div id="container">
<div id="logocontainer">    
<a href="/"> <img src="images/logo.svg" alt="Logo." /> </a>
</div>      
</div>  

#container {
    background-color: black;
    z-index: 0;
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
}

#logocontainer {
    position: fixed;
    margin: 0 auto;
    z-index: 1;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    width: 50%;
    height: 100%;
    display: inline-block;
    vertical-align: middle;
    align-items: center;
    justify-content: center;
    text-align: center;
}

#logocontainer img {
    width: 100%;
}

Viewing all articles
Browse latest Browse all 72443

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>