0

Is it possible to have the content of a div vertically centred?

<div style="padding-left: 15px; vertical-align: middle; align-content: center" >
      <h3>Selections</h3>
</div>

I want the text left aligned and in the vertical middle

user2868835
  • 829
  • 1
  • 16
  • 27

4 Answers4

1

I gave you an example of vertical alignment using flex rules. In this case, the vertical alignment occurs with the help of an align-item: center. Also, you need space for vertical alignment.

body {
   padding: 0;
   margin: 0;
   box-sizing: border-box;
}

div {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}
<div>
   <h3>Selections</h3>
</div>
s.kuznetsov
  • 14,440
  • 3
  • 9
  • 22
0

Well it's an easy property you can set. You can set the text-align property. You can read more about this below.

https://www.w3schools.com/cssref/pr_text_text-align.ASP

for vertical centering:

https://www.w3schools.com/css/css_align.asp

StuiterSlurf
  • 2,115
  • 3
  • 25
  • 50
0

You want to use the CSS property text-align. Also remove the inline 'style' you have on your div and use a css file

.center-content {
     text-align: center;
     width: 100%;
}
<div class="center-content">
     hello world
</div>
AGE
  • 3,604
  • 3
  • 35
  • 58
0

If you are oke with setting the height of the h3 tag, you can do this:

h3{
  height: 4%;
  margin-top: 48%;
  margin-bottom: 48%;
}

Otherwise do this;

h3{
  margin-top: 50%;
  margin-bottom: 50%;
}
M.DeBaecke
  • 83
  • 1
  • 10