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

Why child div is shifted some pixels down and some pixels left from the parent div?

Child div is shifted some pixels down and some pixels left from the parent. I am concerned about the class "yellow" that is child of class "red". Here is my code:

div{
    width:100px;
    height:100px;
    border:solid 2px;
}

.red{
    background-color:red;

}
.yellow{
    background-color:yellow;
}
.green{
  background-color:green;
}
<div class="red">red
  <div class="yellow">yellow</div>
</div>
<div class="green">green</div>

>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

border:solid 2px; is the reason, here child div border width 2px is occupying space.

Replace border with an outline like below

div{
    width:100px;
    height:100px;
    outline:solid 2px;
}

.red{
    background-color:red;

}
.yellow{
    background-color:yellow;
}
.green{
  background-color:green;
}
<div class="red">red
  <div class="yellow">yellow</div>
</div>
<div class="green">green</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