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 >
<p >Signature for acceptance</p>
<p >__________________________________</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?
CodePudding user response:
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.
CodePudding user response:
With text-align: center;
you can archive this.
.divsignature {
margin-left: auto;
margin-right: 0;
width:40%;
}
.signature {}
.signaturetext {
text-align:center;
}
<div >
<p >Signature for acceptance</p>
<p >__________________________________</p>
</div>
CodePudding user response:
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 >
<p >Signature for acceptance</p>
<p >__________________________________</p>
</div>
CodePudding user response:
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 >
<p >Signature for acceptance</p>
<p >__________________________________</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 >
<div >
<div >Signature for acceptance</div>
<div ></div>
</div>
</div>