1

hope you are all well.

I have 2 divs that are inline to each other. But for some reason, the div on the right has this weird margin at the top. How do I make both divs stick at the top without any sort of weird margins? Also I would like to know what went wrong.

link to jsfiddle - https://jsfiddle.net/vynd2k85/1/

Thanks in advance!

.context {
  box-sizing: border-box;
  width:49%;
  padding: 10px;
  background: #72ED80;
  font-family: 'Source Sans Pro', sans-serif;
  display: inline-block;
  margin: 0;
}
.context h1 {
  text-align: left;
  font-size: 14px;
}
.context ul li {font-style: normal; margin: 0; font-size: 14px; line-height: 150%;}
billybobjones
  • 513
  • 1
  • 7
  • 16

2 Answers2

4

It's not a margin, it the vertical alignment. Just add vertical-align:top to your content class:

.context {
    box-sizing: border-box;
    width:49%;
    padding: 10px;
    background: #72ED80;
    font-family:'Source Sans Pro', sans-serif;
    display: inline-block;
    margin: 0;
    vertical-align:top;
}

jsFiddle example

The default vertical align value is baseline, which is what you're seeing.

Community
  • 1
  • 1
j08691
  • 204,283
  • 31
  • 260
  • 272
1

See the updated fiddle.

https://jsfiddle.net/a1L8tugz/

The issue here is that by default, making a div inline will align it to the bottom so you need to add vertical alignment like so.

.context {
box-sizing: border-box;
width:49%;
padding: 10px;
background: #72ED80;
font-family: 'Source Sans Pro', sans-serif;
display: inline-block;
margin: 0;
vertical-align: top; 
}
TheLimeTrees
  • 413
  • 6
  • 20