Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Div to stay in the center of page [duplicate]

Original

I am new to CSS, how i can make the div stay at the center of the page like this?

Desired

<div class="container">
    <div class="row">
        <div class="col-md-2">

        </div>
        <div class="col-md-8 center-block">
            <img class="img-responsive" id="MainCharacter" src="../Images/test_character.png" />
        </div>
        <div class="col-md-2">

        </div>
    </div>
</div>
like image 670
BernardWong Avatar asked Oct 30 '22 08:10

BernardWong


1 Answers

Use CSS similar to this:

.container{
  position: relative;
}

.row {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}

A possible problem is that this code will apply to all .container's and .rows. You could add an id to them and select it using that id.

like image 121
Chris Happy Avatar answered Nov 01 '22 03:11

Chris Happy