0

I'm just starting to study responsive web designing. In my situation, I have a <wrapper> that is needed to be in the center of the screen in any kind of mobile device. I have managed to center it horizontally, but the vertical position can't be centered. Is it possible to center a div vertically?

These are my codes:

CSS

@media (max-width: 480px) and (min-width: 320px) {
    #wrapper{
        top: 10%;
        left: 5%;
        padding-bottom: 3%;
        position: relative;
        width: 90%;
    }

HTML

<div id="wrapper">
    <div id="box">
        <hr>
        <h2> O N L I N E<br>R E S U M E</h2>
        <hr>
        <p><b>Sample</b></p>
        <p>Sample</p>
        <p>E-mail Address: <a href="mailto:">sample@yahoo.com.ph</a></p>
    </div>
    <div id="navi">
    <center>
        <a class="link" id="resume" href="Resume.html">R E S U M E</a> 
        <a class="link" id="port" href="#">P O R T F O L I O</a> 
        <a class="link" id="contact" href="Contact.html">C O N T A C T</a> 
    </center>
    </div>
</div>
Jennifer
  • 1,291
  • 1
  • 11
  • 16

3 Answers3

0

Apply this style:

div.center{
   position: absolute;
   margin: auto;
   top: 0;
   left: 0;
   bottom: 0;
   right: 0;
}
Pavel Gatnar
  • 3,987
  • 2
  • 19
  • 29
0

Hey try with below code at @media ()

 /* Parent */   
 body {
     position: absolute;
     display: table;
     width: 100%;
     height:100%;
 }

 /* Child */
 #wrapper {
     display: table-cell;
     vertical-align: middle;
 }

Good Luck

lwinkyawmyat
  • 1,221
  • 1
  • 16
  • 34
0

HTML

<div>
  testing!
</div>

CSS

div{
  background: #222;
  color:#FFF; 
  bottom: 0;
  height: 100px;
  left: 0;
  margin: auto;
  position: absolute;
  top: 0;
  right: 0;
  width: 100px;
}
Ravimallya
  • 6,550
  • 2
  • 41
  • 75
Ravi Chauhan
  • 1,409
  • 13
  • 26