Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Aligning an odd-width child within an even-width parent

In parent block with even block width value –
is it possible to position (or align) in the middle
this parent is a child with an odd width value?
For example, take a parent with a width of 10 pixels and a child with a width of 1 pixel.
Is it possible to position the child in the middle of such a parent?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Yes, This can be done using translateX. The function takes float values.

.parent{
width:10px;
height:10px;
background:black;
}
.child{
width:1px;
height:10px;
background:red;
transform:translateX(4.5px);
}
<div class="parent">
  <div class="child">
  </div>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading