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

How to add margin from last div class?

I have three div classes. something like this

.first {border: 1px solid #ccc; width: 800px}
.second {width:200px;float:left;}
.third {margin-left:10px}

<div class="first"><div class="second"><img src="https://dummyimage.com/200x300"></div><div class="third">test</div>

here second div shows from the left side. I want the third div class margin-left count from the second div class. is it possible?

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

>Solution :

You can easly make them stay next to each other using display: flex; at parent element
and add flex-shrink: 0; at image container to prevent it from lose width if sibling(element with text) is too big

.first
{
  border: 1px solid #ccc;
  width: 800px;
  display: flex;
}
.second
{
  width:200px;
  flex-shrink: 0;
}
.third
{
  margin-left:10px
}
<html>
<body>

<div class="first">
  <div class="second">
    <img src="https://dummyimage.com/200x300">
  </div>
  <div class="third">
    test
  </div>
</div>

</body>
</html>
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