0

I have a popup window and I have 2 <p> within a <div> the div has padding-left & padding-right and I want to put the p tags in the center of the div. how should I do it?

here is the code:

<div class="sign"><p class="sign_text"> ' + sign + '</p> <p class="sign_text"> ' + this.sender + '</p> <div>

the style

'.sign{padding-left: ' + this.sign_padding_left + ';' +
  'padding-right: ' + this.sign_padding_right + ' +; font-family: IRANSharp;}' + 
  '.sign_text{margin-bottom: 0px; text-align: center}</style>'

this is what I want, but it shouldn't be in the center of the page, I want this part to have left and right paddings

fariba.j
  • 1,737
  • 7
  • 23
  • 42

3 Answers3

2

Add this css

.sign{
  display: flex;
  flex-direction: column;
  justify-content: center; // align horizontally center
  aligns-items: center;  // align vertically center
}

Edit 1: Based on the image you have added

.sign{
  display: flex;
  align-items: flex-start;
  justify-content: center;
  flex-direction: column;
}

p{
  display:block;
  text-align:center;
  width: 80%; /*Change this for left adjustment*/
}
Arvind Muthuraman
  • 2,957
  • 1
  • 12
  • 11
0

This to me is a great use for flexbox.

Try something like this:

div {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

p { // use a class obviously
  display: inline-block;
}

This is a great resource for flexbox https://css-tricks.com/snippets/css/a-guide-to-flexbox/

Brett East
  • 4,022
  • 2
  • 20
  • 31
0

Just add { display: block; } to .sign class then text-align will work.

MontyGoldy
  • 739
  • 1
  • 13
  • 25