-1

I have this:

#rightHeader {
  height: 450px;
  vertical-align: middle;
  display: inline-block;
}
<div id="header" class="header">
    <div class="container">
        <div class="row">
            <div id="headerBox" class="col-md-5 text-center">
                <form id="signup" action="" method="post">
                <h1>text</h1>
                <p>text</p>
                <input id="inputField1" class="form-control" placeholder="First Name" type="text" tabindex="1" required>
                <input id="inputField2"  class="form-control" placeholder="Your Email" type="email" tabindex="1" required>
                <input id="inputField2"  class="form-control" placeholder="Password" type="email" tabindex="1" required><br>
                <button class="btn btn-lg btn-primary">Join For Free</button>
                </form>
            </div>
            <div id="rightHeader" class="col-lg-7 text-center">
                <ul>
                    <li>text.</li>
                </ul>
            </div>
        </div>
    </div>
</div>

For the rightHeader text I have to use margin-top just to make the text visible (otherwise it's too high and goes off the screen). How can I verticallycenter the text in the div without using margin-top?

Thanks

Joe Sgg
  • 71
  • 3
  • 8

3 Answers3

2

#rightHeader {
  height: 450px;
  vertical-align: middle;
  display: inline-block;
  align-items:center;
  justify-content:center;
  display:flex;
  border:thin black solid;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div id="header" class="header">
    <div class="container">
        <div class="row">
            <div id="headerBox" class="col-md-5 text-center">
                <form id="signup" action="" method="post">
                <h1>text</h1>
                <p>text</p>
                <input id="inputField1" class="form-control" placeholder="First Name" type="text" tabindex="1" required>
                <input id="inputField2"  class="form-control" placeholder="Your Email" type="email" tabindex="1" required>
                <input id="inputField2"  class="form-control" placeholder="Password" type="email" tabindex="1" required><br>
                <button class="btn btn-lg btn-primary">Join For Free</button>
                </form>
            </div>
            <div id="rightHeader" class="col-lg-7 text-center">
                <ul>
                    <li>text.</li>
                </ul>
            </div>
        </div>
    </div>
</div>

Is this the same that you are looking for?

Hope this helps.

Bhavin Shah
  • 2,462
  • 4
  • 22
  • 35
0

Have a look at CSS3 flexbox. You can do a lot of with it. This should be it:

#rightHeader {
  height: 200px;
  display: flex;
  align-items: center;
  border: 1px solid #666;
}
<div id="rightHeader" class="col-lg-7 text-center">
    <ul>
        <li>text.</li>
    </ul>
</div>
Schlumpf
  • 358
  • 1
  • 3
  • 13
0

I use the line-height property and then reset it on the child element

#rightHeader {
  height: 300px;
  width: 250px;
  line-height: 300px; /* same as div height */
  display: inline-block;
  background: #999;
  text-align: center;
}

#rightHeader ul {
  padding: 1px;
  display: inline-block;
  line-height: normal; /* reset it here */
}
<div id="rightHeader" class="col-lg-7 text-center">
  <ul>
    <li>text.</li>
  </ul>
</div>
I haz kode
  • 1,587
  • 3
  • 19
  • 39