Here is the script: https://jsfiddle.net/3h71kzxe/5/
.holder{ width: 100%; background: tomato; height: 200px; line-height: 200px; position:relative; } .holder::after{ content: ""; border: 1px solid red; background: transparent url('my-img.jpg') no-repeat; width:30px; height: 30px; display: block; position:absolute; right:0; top:0; bottom:0; margin: auto 0; }
Explanation:
To shift: after the element from right to right: 0 is added, but before that we need to set it as absolute, and the parental position must be relative in order to do the work of the absolute position relative to the field of its parents.
top:0, bottom:0 and margin:0 auto; should make it vertically in the center, above: 0 and below: 0 will stretch the: after element to make it 100% high, but since we gave a height of 30 pixels; and margin: 0 auto; it will result in: after the element in the vertical center.
source share