Reputation: 2587
Here is My Demo
<span class="boxPrice ">
<p>Previous Bill</p>
</span>
I want to create <p>
inside a <span>
should be vertically aligned center inside the <span>
Upvotes: 1
Views: 95
Reputation: 161
.boxPrice
{
width:160px; height:75px; border:1px #333 solid; text-align:center; display:inline-block;}
.boxPrice p{padding:20px !important; margin:0 !important}
.boxPrice:after{ display:inline-block; content:'';vertical-align:middle; height:100%}
Upvotes: 0
Reputation: 11148
Block elements aren't "affected" by the vertical-align: middle
, only inline elements...
I suggest changing the p
to inline and adding the vertical-align: middle
, like this:
.boxPrice p {
padding:0 !important;
margin:0 !important;
display: inline;
vertical-align:middle;
}
Upvotes: 1
Reputation: 589
I would rather not use a block level element ("p") element within an inline level element ("span"). Use div instead.
There are several tricks on how to do this, the simplest is to modify line-height to match the height of your container:
.container { width: 100px; height: 100px; line-height: 100px; /* Set it to the container height */ }
You can also use "display: table-cell" to achieve the same effect:
.container {
display: table-cell;
vertical-align: middle;
}
Upvotes: 1
Reputation: 6499
Add line-height:75px;
You need to make sure the line height is the same as the div height/
Upvotes: 2