1

I try to to set vertical align of elements that exist into a div tag to center. Please advice

<div class="new_div">
     <h3>نام من</h3>
    <p>توضیحات من</p>
    <button class="btn btn-primary">بیشتر ...</button>
</div>

css

.new_div {
    position: absolute;
    width: 100%;
    text-align: center;
}
Alex
  • 8,461
  • 6
  • 37
  • 49
hmahdavi
  • 2,250
  • 3
  • 38
  • 90

3 Answers3

1

For vertical center? Try something along the lines of

.new_div {
   width: 100%;
   height: 100px;
   line-height: 100px; /* Same as new_div height */
 }
Liam Macmillan
  • 388
  • 1
  • 5
  • 13
1

You can use display: table-cell;

Jsfiddle

body,
html {
  position: relative;
  margin: 0;
  padding: 0;
}
.new_div {
  position: absolute;
  width: 100%;
  text-align: center;
  display: table;
  height: 200px;
  background-color: red;
}
.container {
  display: table-cell;
  vertical-align: middle;
}
<div class="new_div">
  <div class="container">
    <h3>نام من</h3>
    <p>توضیحات من</p>
    <button class="btn btn-primary">بیشتر ...</button>
  </div>
</div>
Hynes
  • 3,394
  • 3
  • 22
  • 22
Alex
  • 8,461
  • 6
  • 37
  • 49
0

You could try to

  • use the display attribute
  • in combination with the vertical-align attribute

    <div style="display: table; height: 400px; overflow: hidden;">
        <div style="display: table-cell; vertical-align: middle;">
          <div>
            <h3>نام من</h3>
            <p>توضیحات من </p>
            <button class="btn btn-primary">بیشتر ...</button>
          </div>
       </div>
    </div>
Minzkraut
  • 2,149
  • 25
  • 31