-2

Let me know how to align text in the center of 'p' element.

I think Aligning text in p element is not same as aligning text in div element.

<!DOCTYPE html>
        <html>
        <style>
        #element{
            background: #95CFEF;
            border: solid 1px #36F;
            width: 300px;
            height: 100px;
            margin: 10px auto;
         text-align: center;
        }
        </style>
        <body>
        <p id = "element">This is some text in a paragraph.</p>
        </body>
        </html>

Thanks in advance

https://jsfiddle.net/sri276286/w65jLzv9/

I am expecting like this:

enter image description here

srikanth_k
  • 2,807
  • 3
  • 16
  • 18

2 Answers2

0

Why don't you try line-height: 100px;

Basically line-height should be same as your #element's height

Saurabh Bayani
  • 3,350
  • 2
  • 25
  • 44
-2

It's not id = "element", it's id="element" mind the spaces. This could fix your problem. If you meant vertical align let me know and I'll come back on that

GreyRoofPigeon
  • 17,833
  • 4
  • 36
  • 59
  • That's not a big deal. I tried removing that space but still issue. I want that text to be exactly at center of that paragraph element – srikanth_k Jun 06 '16 at 14:33
  • This is not useful - Those are equivalent (the spacing change has no impact) You can prove it to yourself in a simple jsfiddle. – Krease Jun 06 '16 at 14:39