I would like to display a symbol (⌂
) and put a number inside (this is for a home dashboard and is supposed to give the temperature inside the house).
I know about absolute positioning but it looks like that the position, despite being relative to a known parent, has to be in absolute values (in px for instance).
It means that in the example below, I need to adjust (increase) the left: 1px;
value until it is visually centered:
.house {
font-size: 500%;
position: relative;
}
.temp {
font-size: 25px;
position: absolute;
top: 40px;
left: 1px;
}
<div class="house">
⌂
<div class="temp">13</div>
</div>
I was hoping for an "absolute, relative to the parent dimensions" setting, in % (or other relative measurements). Is this possible?
Since this is a one-shot adjustment in my case (the dashboard is mine, it does not change and I can fiddle manually with this value) I will probably go fo the visually "good enough" solution, but I would be glad to use something more flexible.
Another possibility is to make the calculations in JS (it I feasible since I am using a JS framework anyway, but I am surprised there is no pure CSS solution)
4
Answers
Fist of all add something like
to the parent (.house) so this won’t happen:
after that just position the child relative (%)
I changed the vertical center to px for this example (because the middle of the house is not in the center):
I think following could be flexible if not what you’re looking for.
use flex display:
Build that symbol using CSS: