3

I noticed something that I could not understand.

https://getbootstrap.com/docs/3.4/css/#forms-inline

Where is the this gap between the 'label' and the 'input' coming from?

Both of them are inline. Are they supposed to attach each other?

I actually copy the code into my project. They are attached to each other. But my project is messy. I want to understand why on the bootstrap website, they are not attached.

They are 'inline-block'. In their 'Computed' tab, the margin is '-'. So zero. Right?

Where is this margin coming from? enter image description here

Hao
  • 5,661
  • 9
  • 34
  • 74

2 Answers2

1

This space is coming from inline-block property, it's adding some space between elements which is inlined by default,

See This Example with no libraries added

 div { 
      display: inline-block;
      font-size: 2rem;
    }
    div:nth-child(odd) { 
      background-color: lightblue
    }
    div:nth-child(even) { 
      background-color: lightcoral;
    }
    <div>abc</div>
    <div>abc</div>
    <div>abc</div>
    <div>abc</div>
Kareem Dabbeet
  • 3,008
  • 2
  • 10
  • 29
0

From CSS-Tricks.com:

This isn't a "bug" (I don't think). It's just the way setting elements on a line works. You want spaces between words that you type to be spaces right? The spaces between these blocks are just like spaces between words. That's not to say the spec couldn't be updated to say that spaces between inline-block elements should be nothing, but I'm fairly certain that is a huge can of worms that is unlikely to ever happen.

Read More

Pateman
  • 2,516
  • 3
  • 25
  • 35
Sumit Patel
  • 4,192
  • 1
  • 6
  • 25