Vertical centering in CSS
is relatively straight forward. This is the code I'm using.
position:relative;
top:50%;
transform:translateY(-50%);
1) This works great for centering multiple shapes next to each other.
2) It works great for centering multiple words next to each other.
However oddly enough when I place a centered shape next to a centered word it goes haywire. Is there an obvious, or not so obvious reason for this? How do I fix it?
I created a fiddle so you can see the result. https://jsfiddle.net/9h1pfpns/
Here is my code:
.container {
height: 200px;
margin: 10px;
border: 4px solid #754419;
}
.shape {
display: inline-block;
position: relative;
top: 50%;
transform: translateY(-50%);
width: 250px;
height: 100px;
margin-left: 10px;
background-color: aquamarine;
}
.text {
display: inline-block;
position: relative;
top: 50%;
transform: translateY(-50%);
font: bold 1.25em Arial, Helvetica, sans-serif;
margin-left: 10px;
border: 1px solid #754419;
}
<div class="container">
<div class="shape"></div>
<div class="text">first</div>
</div>