-1

.center {
  height: 200px;
  border: 3px solid green;
  text-align: center;
  vertical-align: middle;
}

p {
  margin: 0;
  padding: 0;
}
<div class="center">
  <p>I am vertically and horizontally centered.</p>
  <p>I am vertically and horizontally centered.</p>
</div>

How do I make the lines vertically-centered? Thank you in advance! I

VXp
  • 10,307
  • 6
  • 25
  • 40
zzz
  • 29
  • 5

3 Answers3

1

Flexbox solution:

.center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 3px solid green;
  height: 200px;
}

p {
  margin: 0;
  padding: 0; 
}
<div class="center">
  <p>I am vertically and horizontally centered.</p>
  <p>I am vertically and horizontally centered.</p>
</div>
VXp
  • 10,307
  • 6
  • 25
  • 40
Nandita Sharma
  • 12,347
  • 2
  • 14
  • 26
1

You can use display: flex:

.center {
  height: 200px;
  border: 3px solid green;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center
}

p {
  border: 1px solid red;
  margin: 0;
  padding: 0;
}
<div class="center">
  <p>I am vertically and horizontally centered. </p>
  <p>I am vertically and horizontally centered. </p>
</div>
Adam
  • 1,366
  • 8
  • 22
0

Please Try this Code

.center {
    height: 200px;
    border: 3px solid green;
    width: 100%;
    text-align: center;
    vertical-align: middle;
    display: table-cell;
    vertical-align: middle;
}

p {
    margin: 0px;
    padding: 0px;        
}
<div class="center">
  <p>I am vertically and horizontally centered. </p>
  <p>I am vertically and horizontally centered. </p>
</div> 
Dhaval Patel
  • 102
  • 6