0

I am trying to align a line of text and a Bootstrap button, vertically and horizontally. The height of the div is set using vh. I know there are other answers for this question on here, but I couldn't get them to properly center.

#centertext {
  text-align: center;
  height: 30vh;
}
<div class="container" id="centertext">
  <h4> Want to download a more detailed version of my resume?</h4>
  <a href="#" class="btn btn-primary">
    <span class="glyphicon glyphicon-file"></span>     Download
  </a>        
</div>
jacefarm
  • 6,747
  • 6
  • 36
  • 46
adobesmurf
  • 33
  • 1
  • 7

4 Answers4

1

Try this:

* {
  padding: 0;
  margin: 0;
} /* Resets all default margins */

h4 {  margin-bottom: 1.33em  }

#centertext {
  text-align: center;
  height: 30vh;
  background: red;
  position: relative;
}

#centertext .wrapper {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: white;
}
<div class="container" id="centertext">
  <div class="wrapper">
    <h4> Want to download a more detailed version of my resume?</h4>
    <a href="#" class="btn btn-primary">
      <span class="glyphicon glyphicon-file"></span> Download
    </a>

  </div>
</div>
Chris Happy
  • 7,088
  • 2
  • 22
  • 49
0

try this code..

http://codepen.io/gmkhussain/pen/MJYmVX

#centertext {
  height: 300px;
  line-height: 300px;
  text-align: center;
  border: 2px dashed #39c;
}
.inr {
  display: inline-block;
  vertical-align: middle;
  line-height: normal;
}
GMKHussain
  • 3,342
  • 1
  • 21
  • 19
0

Try this used display: flex; styling.

#centertext {
  text-align: center;
  height: 30vh;
  vertical-align: middle;
  float: none;
  background-color: grey;
  display: flex;
  justify-content: center;
  flex-direction: column;
}
#centertext .btn-primary,
#centertext h4 {
  margin: 0 auto;
}
body {
  background-color: white;
}
<br>
<div class="container" id="centertext">
  <h4> Want to download a more detailed version of my resume?</h4>
  <a href="#" class="btn btn-primary"><span class="glyphicon glyphicon-file"></span> Download</a>
</div>
aavrug
  • 1,849
  • 1
  • 12
  • 20
0

This worked for me the second div allows for more styling and this answer is a variation from this questions answer but this one displays properly.

Thanks to @GMK Hussain

#centertext {
  height: 300px;
  line-height: 300px;
  text-align: center;
  border: 2px dashed #39c;
}
.inr {
  display: inline-block;
  vertical-align: middle;
  line-height: normal;
}
Community
  • 1
  • 1
adobesmurf
  • 33
  • 1
  • 7