center a "position: absolute" element - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Absolute Position

Description

center a "position: absolute" element

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <style id="compiled-css" type="text/css">
body {<!--from w w  w  . j a  v  a2  s.c o  m-->
   text-align:center;
}

#slideshowWrapper {
   margin-top:51px;
   text-align:center;
   width:501px;
}

ul#slideshow {
   list-style:none;
   position:relative;
   margin:0 auto;
}

ul#slideshow li {
   position:relative;
   left:51%;
   display:block;
}

ul#slideshow li img {
   border:2px solid Chartreuse;
   padding:5px;
   height:451px;
}
</style> 
 </head> 
 <body> 
  <div id="slideshowWrapper"> 
   <ul id="slideshow"> 
    <li> <img src="https://www.java2s.com/style/demo/InternetExplorer.png" alt="Dummy 1"> </li> 
    <li> <img src="https://www.java2s.com/style/demo/Google-Chrome.png" alt="Dummy 2"> </li> 
   </ul> 
  </div>  
 </body>
</html>

Related Tutorials