Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
773 views
in Technique[技术] by (71.8m points)

html - Vertical Align an element in CSS

Dear experts, I was trying to align an paragraph to the middle of an division element via CSS and I somehow can't get it to work.

 <style type="text/css">
    .wrap{
background:red;
height: 5em;  
     }
     p{
     background:blue; 
        height: 2em; 
vertical-align:middle; 

      }
  </style>


<div class="wrap">
    <p>
    ALIGN TEXT
    </p>
</div>

It doesn't work in IE nor firefox,

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here's a nice hackish example, i'd put the IE css in conditionals instead of hiding it with hacks, other that that nice.

  <div style="display: table; height: 400px; #position: relative; overflow: hidden;">
    <div style=" #position: absolute; #top: 50%;display: table-cell; vertical-align: middle;">
      <div class="greenBorder" style=" #position: relative; #top: -50%">
        any text<br>
        any height<br>
        any content, for example generated from DB<br>
        everything is vertically centered
      </div>
    </div>
  </div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...