May be a simple one but I want to align the prices in the centre of the grey circles. The grey circle is within a span class, and I have read on some tutorials that it is tricky to align something central within a span compared to a div? But I just can’t get my head around the positioning of these items, I have to set one to relative and absolute, or is this not the best way to do it?
If someone could explain how I can do this so I can learn it and make sure I can do it myself.
.process-icon is the container for the background image and price. It has fixed dimensions. The fixed height is important to note because a fixed height container is required for this technique to work.
Inline items align to their baseline by default (like words in a sentence). In this technique, we set the display property of the <h4> box to inline-block and add {vertical-align:middle}. However, that alone doesn’t change the vertical position of <h4>. It needs a peer, a reference, with which to align that will cause it to align in the middle of the .process-icon box.
We give it a reference by using :before or :after to add a zero width box inside .process-icon and give that box a display property of inline-block and a height of 100% which causes it to extend to the full height of its parent container (.process-icon). Finally, we give it {vertical-align:middle} which causes the <h4> to align in the middle of the .process-icon box.
You can see that reference box by adding a 1px outline to the .process-icon:after code. (I use outlines a lot while coding. )
The greater-than symbol, “>” , is the immediate child (first generation child) selector. It selects all <h4> tags that are the immediate children of the .process-icon.
<div class="process-icon">
<h4>price</h4> <!-- With the ">" selector, only this first generation <h4> is targeted. -->
<div>
<h4>another h4</h4> <!-- Without it, all generations of <h4> are targeted. -->
</div>
</div>
I tend to add specifiers like that to minimize undesired interaction that I may be unaware of. In your code, it is probably not needed.