Sarah
Sarah

Reputation: 285

How to put the first p tag in the middle of the second p tag below it

I need to column align the two p tags on the right of the screen, as shown in the code below:

.divsignature{
  font-weight: bold;
  float:right;
  }

.signature{
  padding: 15px 30px 10px 0px;
}
<div class="divsignature">
  <p class="signaturetext">Signature for acceptance</p>
  <p class="signature">__________________________________</p>
</div>

But I want the writing "Signature for acceptance" to be in the center with respect to the line below, i.e. with respect to the p tag with class signature.

Can anyone kindly help me?

Upvotes: 2

Views: 72

Answers (4)

Mark Schultheiss
Mark Schultheiss

Reputation: 34168

You can modify the container (body) and use flex. I modified from px so if you scale the space scales with it.

   /* use whatever the container is for divsignature instead of body here */
body {
  display: flex;
  justify-content: end;
}

.divsignature {
  font-weight: bold;
  display: flex;
  flex-direction: column;
  justify-content: center;
  /* center the label above the line */
  text-align: center;
}

.signature {
  padding-top: 1em 2em 0.625em 0;
}
<div class="divsignature">
  <p class="signaturetext">Signature for acceptance</p>
  <p class="signature">__________________________________</p>
</div>

Here is a potential alternative using a grid, no text for the line just a border; space can change with font size etc. Comments in the CSS for related fun things.

.signature-container {
  display: grid;
}

.divsignature {
  justify-self: end;
  display: grid;
  /* this 3.5em is the height of the "line" block */
  grid-template-rows: 1fr 3.5em;
  /* this can be here or width:20em; on the .signature */
  grid-template-columns: 20em;
  text-align: center;
}

.signaturetext {
  /* just to show the effect, not needed for the positioning */
  font-size: 1.2rem;
  color: #2222ff;
  font-weight: 600;
}

.signature {
  border-bottom: solid 0.0625em black;
  /* just to see what we have here */
  background-color: #ddddff33;
}
<div class="signature-container">
  <div class="divsignature">
    <div class="signaturetext">Signature for acceptance</div>
    <div class="signature"></div>
  </div>
</div>

Upvotes: 1

O&#39;con
O&#39;con

Reputation: 184

Problem: There is no styling that would center the text in your css, so we need to add that.

Solution: You need to add styling in order to center the text, which can be achieved by using text-align:center.

.divsignature{
  font-weight: bold;
  float:right;
  }

.signaturetext{
  text-align:center;
}
<div class="divsignature">
  <p class="signaturetext">Signature for acceptance</p>
  <p class="signature">__________________________________</p>
</div>

Upvotes: 0

Maik Lowrey
Maik Lowrey

Reputation: 17556

With text-align: center; you can archive this.

.divsignature {
  margin-left: auto; 
  margin-right: 0;
  width:40%;
}

.signature {}

.signaturetext {
  text-align:center;
}
<div class="divsignature">
  <p class="signaturetext">Signature for acceptance</p>
  <p class="signature">__________________________________</p>
</div>

Upvotes: 0

Bernard Borg
Bernard Borg

Reputation: 1372

Use this;

.divsignature{
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    font-weight: bold;
    float: right;
}

/* Remove the .signature padding */

or

.divsignature {
    text-align: center;
    font-weight: bold;
}

.signaturetext {
    text-align: center;
}

/* Remove the .signature padding */

Whichever works best for you.

Upvotes: 3

Related Questions